You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi!

    I'd say you'd probably find it easier having just Bangle.on('twist',twistctrl); and then putting all your code in twistctrl (rather than adding/removing countup as needed). I think that could really tidy things up for you, and might fix some of the quirkiness.

  • Thanks a lot for pointing me in the right direction. I lacked the knowledge to realize that I don't need a second Bangle.on('twist'). And now I realize my newbie question is quite senseless, because a bit more of "if...else-understanding" gets the job done easily.

    So here is the less function-cluttered "app":

    /////////////////////////////////////////////////////////////
    //   control music by twist/buttons
    
    let counter = 0; //stores your counted your twists
    var tstate = false; //are you ready to count the twists?
    
    function playx() {
      Bluetooth.println(JSON.stringify({t:"music", n:"play"}));
    }
    
    function volu() {
      Bluetooth.println(JSON.stringify({t:"music", n:"volumeup"}));
    }
    
    function vold() {
      Bluetooth.println(JSON.stringify({t:"music", n:"volumedown"}));
    }
    
    function sendCmd() {
      print (counter);
      Bangle.beep(200,3000);
      if (tstate==false && counter>0){
      do {playx(); counter--;}
      while (counter >= 1);
      }
    }
    
    function twistctrl() {
      if (tstate==false){
        tstate=true;
        setTimeout('tstate=false',4000);
        setTimeout(sendCmd,4100);
        Bangle.beep(200,3000);
      }
      else{
      if (tstate==true){
      if (counter < 5){
        counter++;
        Bangle.buzz(100,2);
        }
      else {
        counter = 0;
        Bangle.buzz(400);
           }
      }
      }
    }
    
    setWatch(volu,BTN1,{repeat:true});
    setWatch(vold,BTN3,{repeat:true});
    Bangle.on('twist',twistctrl);
    setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
    
About

Avatar for Gordon @Gordon started