• Your final code looks then like:

    var soundOn;
    pinMode(C6,"input_pullup");
    pinMode(C7,"input_pulldown");
    pinMode(A8,"input_pulldown");
    pinMode(C9,"output");
    
    function onInit() {
      analogWrite(C9,0);
      soundOn = false;
      setWatch(function(){
          makeSound(); // 'fixed': added semicolon ;
        },C6,{repeat:false,edge:"falling",deboun­ce:100}); 
    }
    
    function makeSound() {
      if (digitalRead(C7) || digitalRead(A8)) {
        console.log("then - " + getTime());
        if (!soundOn) {
          analogWrite(C9,0.5); // 'fixed' warn'g: added leading 0
          digitalWrite(LED1,1);
          soundOn = true; // 'fixed': added ;
        }
        setTimeout(function(){
            makeSound(); // 'fixed': added ;
          },5*1E3); // 'fixed': added ;
      } else {
        console.log("else - " + getTime());
        if (soundOn) {
          analogWrite(C9,0);
          digitalWrite(LED1,0);
          soundOn = false; // 'fixed': added ;
        }
        setWatch(function(){
            makeSound(); // 'fixed': added ;
          },C6,{repeat:false,edge:"falling",deboun­ce:100}); // 'fixed': added ;
       }
    } // 'fixed' warning: removed unnecessary semicolon ; 
    
    onInit(); // starts code immediately after upload - useful at development time
    

    When you develop/test (without the last line), you upload the code and invoke the onInit() function in the console with a command, or, you can just add as last line ('onInit()') in the code and you have it quicker going. I would though not have the last line in the version of teh code hat you save to the board, because running code may have started timers which may mess up 'your life'...

    So much for the code correctness... ;-).

    To use Espruino through blockly, blockly needs some more work to cover all Espruino specifics.

    Now for your actual case, I have to mentally picture it first, before elaborating on possible code changes.

About

Avatar for allObjects @allObjects started