• Hi
    Love the Espruino. Having loads of fun seeing what it can do. However have issue that is confusing me. Can somone help.

    I wrote the following code...

    var list = [
          {"b":0,"g":0,"r":0,"s":0},
          {"b":0,"g":0,"r":1,"s":45},
          {"b":0,"g":1,"r":0,"s":90},
          {"b":0,"g":1,"r":1,"s":135},
          {"b":1,"g":0,"r":0,"s":180},
          {"b":1,"g":0,"r":1,"s":120},
          {"b":1,"g":1,"r":0,"s":90},
          {"b":1,"g":1,"r":1,"s":60}
        ];
    var MIN_SERVO = 0.63;
    var MAX_SERVO = 2.34;
    var ONE_DEG = (MAX_SERVO - MIN_SERVO) / 180;
    var ZERO_DEG = MIN_SERVO;
    var step = 0;
    
    function posServo(deg) {
      return E.clip(MIN_SERVO + (ONE_DEG * deg), MIN_SERVO, MAX_SERVO);
    }
    
    var servoPos = posServo(0);
    
    function stopTimer() {
      if (timer) {
        clearInterval(timer);
        timer = undefined;
      }
    }
    
    function nextLights() {
      digitalWrite(LED1, list[step].r);
      digitalWrite(LED2, list[step].g);
      digitalWrite(LED3, list[step].b);
      servoPos = posServo(list[step].s);
      step = (step +1) % list.length;
    }
    
    var timer = setInterval(nextLights, 500);
    
    setWatch(function() {
      stopTimer();
      nextLights();
    }, BTN1, {"repeat":true,"edge":"rising","debounce":10});
    
    var sp = setInterval("digitalPulse(C5,1,servoPos)", 20);
    

    This works fine, my lights blink, my servo moves...
    When I save() and reset the code does not start! However if I press the button it does get to the setWatch function and the device works from there.
    If I do a dump() however there are some confusing changes to the code.

    var list = [
          {"b":0,"g":0,"r":0,"s":0},
          {"b":0,"g":0,"r":1,"s":45},
          {"b":0,"g":1,"r":0,"s":90},
          {"b":0,"g":1,"r":1,"s":135},
          {"b":1,"g":0,"r":0,"s":180},
          {"b":1,"g":0,"r":1,"s":120},
          {"b":1,"g":1,"r":0,"s":90},
          {"b":1,"g":1,"r":1,"s":60}
        ];
    var MIN_SERVO = 0.63;
    var MAX_SERVO = 2.34;
    var ONE_DEG = 0.0095;
    var ZERO_DEG = MIN_SERVO;
    var step = 5;
    function posServo(deg) {
      return E.clip(MIN_SERVO + (ONE_DEG * deg), MIN_SERVO, MAX_SERVO);
    }
    var servoPos = 2.34;
    function stopTimer() {
      if (timer) {
        clearInterval(timer);
        timer = undefined;
      }
    }
    function nextLights() {
      digitalWrite(LED1, list[step].r);
      digitalWrite(LED2, list[step].g);
      digitalWrite(LED3, list[step].b);
      servoPos = posServo(list[step].s);
      step = (step +1) % list.length;
    }
    var timervar sp = 2;
    setInterval("digitalPulse(C5,1,servoPos)", 19.99950408935546875);
    setWatch(function () {
      stopTimer();
      nextLights();
    }, "B12", { repeat:true, edge:'rising' });
    digitalWrite(A15,1);
    digitalWrite(C5,0);
    

    var step is set to 5, somtimes 7... never 0;
    var servoPos = 2.34. However if I run from console I get the following:

    posServo(0)
    =0.63
    

    also the line

    var timer = setInterval(nextLights, 500);
    

    is re-written as:

    var timervar sp = 2;
    setInterval("digitalPulse(C5,1,servoPos)", 19.99950408935546875);
    

    and the var timer is not set and timervar is introduced. This is a mix of

    var timer = setInterval(nextLights, 500);
    

    and

    var sp = setInterval("digitalPulse(C5,1,servoPos)", 20);
    

    Finally the setWatch parameters are missing the "debounce":10

    I updated to 1v67.. Read some entries in the forum and downgraded to 1v66 but it still does not work.

    When I received Espruino I updated straight away and did not see and evidence of this. that was about a week ago. however in my excitement I did not note which version it upgraded to.

    Currently it works from ram not from flash. If I reset() in the console(), press the reset button, disconnect battery and re-connect or load() in the console it does NOT run.

    It tried minification on and off. It still does not work...

    Can you please help...

    Stuart

About

Avatar for Stuart.d.d @Stuart.d.d started