You are reading a single comment by @rsm and its replies. Click here to read the full conversation.
  • Thanks guys. I tried following your advice to not use blocking code, but ran into another problem. I can't change that value of variables inside the function prototype. For example, this code works:

    setTimeout(function () {analogWrite(B14, 1.6 / 50.0, {freq:20});},1000);
    
    setTimeout(function () {analogWrite(B14, 1.55 / 50.0, {freq:20});},2000);
    
    setTimeout(function () {analogWrite(B14, 1.5 / 50.0, {freq:20});},3000);
    
    setTimeout(function () {analogWrite(B14, 1.45 / 50.0, {freq:20});},4000);
    

    But this code does not:

    var pos = 1.6;
    var posInc = 0.05;
    
    setTimeout(function () {analogWrite(B14, pos / 50.0, {freq:20});},1000);
    pos -= posInc;
    setTimeout(function () {analogWrite(B14, pos / 50.0, {freq:20});},2000);
    pos -= posInc;
    setTimeout(function () {analogWrite(B14, pos / 50.0, {freq:20});},3000);
    pos -= posInc;
    setTimeout(function () {analogWrite(B14, pos / 50.0, {freq:20});},4000);
    

    The result is that it moves to position 1.45 at time 1000. So I guess it has already run "pos -= posInc;" three times before it first calls the analogWrite() function.

    Please help,
    Rehman

About

Avatar for rsm @rsm started