You are reading a single comment by @Jean-Philippe_Rey and its replies. Click here to read the full conversation.
  • Hi guys,

    I just wrote a very basic code aiming at providing the metronome function on the Thingy:52.
    I'm posting it here in case anyone's interested...

    It was inspired by this much more elaborated Bangle.js app.
    However, usage is pretty easy:
    1) a short press on the button increases/decreases the bpm
    2) a long press on the button changes direction of the setting

    The blue led flashes on a long press
    The red led flashes when bpm is reduced
    The green led flashes when bpm is increased

    var dir=1;
    var bpm=60; 
    
    function beep() {
      analogWrite(D27,0.5,{freq:440});
      digitalPulse(D29,1,50);
    }
    
    function onInit()
    {
      setWatch(function(e){
        var isLong = (e.time-e.lastTime)>0.4;
        if(isLong)
        {
          analogWrite(D27,0.5,{freq:392});
          digitalPulse(D29,1,50);
          digitalPulse(LED3,1,100);
          dir=!dir;
        }
        if(dir)
        {
          bpm *=1.1;
          digitalPulse(LED2,1,100);
        }
        else
        {
          bpm *=0.91;
          digitalPulse(LED1,1,100);
        }
        clearInterval(interval);
        interval = setInterval(beep, 60000 / bpm);
      }, BTN1, {repeat:true, debounce:50, edge:"falling"});
    
      interval = setInterval(beep, 60000 / bpm);
      LED2.reset();
    
    }
    
    save();
    
About