You are reading a single comment by @radswid 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:"mus­ic", n:"play"}));
    function volu() {
      Bluetooth.println(JSON.stringify({t:"mus­ic", n:"volumeup"}));
    function vold() {
      Bluetooth.println(JSON.stringify({t:"mus­ic", n:"volumedown"}));
    function sendCmd() {
      print (counter);
      if (tstate==false && counter>0){
      do {playx(); counter--;}
      while (counter >= 1);
    function twistctrl() {
      if (tstate==false){
      if (tstate==true){
      if (counter < 5){
      else {
        counter = 0;;
    setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
  • Wed 2021.05.19

    'I realize my newbie question is quite senseless'

    On the contrary, . . . it was necessary to learn the if-else construct prior to being able to realize that the second twist event would not be required. In your mind before that eureka moment, there wasn't a means to get to that realization, so at that point, creating this post was one of the only means to get to the solution you found. Quite logical when one views this thread thinking the events in reverse.

    Using Gordon's #6 post which is a refinement of the hint I provided in #4 post, allowed you to resolve in a very short period of time the solution I (we) intended you to get to. So, @radswid in around a 24hr period, you were able to comprehend what we were communicating, even though was in more of a hint format, rationalize how that needed to fit into what sequential event sequence wasn't occurring, use intuition and maybe a bit of language syntax learning lookup, in order to present a better structured and simpler coding result, code and debug that solution and all in one evening to-boot!! Are you sure you are a beginner??    ;-)

    Now, please help me here. I'd like to create some tutorials (not related to this project) and have my own references. You indiated in post #3 two references, (the API Reference helped a ton and mozillas MDN JavaScript reference was very helpful too) are there by chance any others that you are using that helped here?

    Now that the final solution is near, there are a couple of observations I'd like to make. Please don't take this as criticism, as it usually takes quite a bit of time before patterns and coding techniques are mastered. And since this solution was found overnight, that hardly fits into
    the 'quite a bit of time' duration.

    Carefully review L36 in post #7 and review examples at MDN:­/Web/JavaScript/Reference/Statements/if.­..else

    The hint here is to simplify. See how that task now may be an improvement.

    I have several others, that we may tackle one-at-a-time.


Avatar for radswid @radswid started