You are reading a single comment by @radswid and its replies. Click here to read the full conversation.
  • Hey there,

    first of all, thanks to everyone who created Bangle.js. Without this piece of hard- and software I would've never started to try writing code.
    In the last two days I tried to write an app (never wrote any code before, I hope it's not too "ugly") to control a music player on Android, which can be controlled by multiple play-commands (1x play / 2x next song / 3x previous song / 4x next folder / 5x previous folder), by a twist of your arm. The idea behind this was: there may be situations when you second hand isn't free, but you wanna change the song you're listening to.

    I had some problems, which I solved very intricately (is this the right word? I'm no native english speaker :sweat_smile: ) I guess.

    Maybe somebody wants to take a look and tell me how to handle things better or less intricate?

    /////////////////////////////////////////////////////////////
    //   control music by twist/buttons
    
    let counter = 0;
    var tstate = false;
    
    // defining commands
    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 resetc() {counter=0;}
    
    function cstate() {
      tstate=!tstate;
      setTimeout(resetc,100);
      Bangle.beep(200,3000);}
    
    function countup() {
      if (counter < 5){
        counter++;
        Bangle.buzz(100,2);
        }
      else {counter = 0;
            Bangle.buzz(400);
           }
    }
    
    function sendCmd() {
      print (counter);
      Bangle.removeListener('twist',countup);
      if (tstate==false && counter>0){
      do {playx(); counter--;}
      while (counter >= 1);
      }
    }
    
    function twistcount() {
      if (tstate==true){
      Bangle.on('twist',countup);
      }
    }
    
    function twistctrl() {
      if (tstate==false)
      {cstate();
      twistcount();
      setTimeout(cstate,4000);
      setTimeout(sendCmd,4100);
      }
    }
    
    setWatch(volu,BTN1,{repeat:true});
    setWatch(vold,BTN3,{repeat:true});
    Bangle.on('twist',twistctrl);
    setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
    

    Is this the right place for this thread, or is "Projects" the better place?

About

Avatar for radswid @radswid started