You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi! It sounds like you figured out the motion detection bit with https://www.espruino.com/Puck.js#on-board-peripherals ?

    So literally all you need to do is mash the two together. For instance using 'Movement detection' from the Puck.js page, and the code from https://www.espruino.com/BLE+Music+Control:

    var controls = require("ble_hid_controls");
    NRF.setServices(undefined, { hid : controls.report });
    
    require("puckjsv2-accel-movement").on();
    var idleTimeout;
    Puck.on('accel',function(a) {
      LED.set();
      if (idleTimeout) clearTimeout(idleTimeout);
      else {
        print("Motion", a);
        controls.next(); // <---------------- HERE
      }
      idleTimeout = setTimeout(function() {
        idleTimeout = undefined;
        LED.reset();
      },500);  
    });
    

    The only trick is making sure you don't call the function too often - so above I only call it the first time it turns the LED on, so you have to wait until the light goes out before you can skip to the next song.

    I guess you could look at acc.z > 0 or something like that so that depending on which way up you help the puck, it played/stopped or skipped song

  • Thank you! I have managed to get this to work using magnetometer, modifying it's sensitivity to movement so that it performs different actions, eg: small move - play/pause, big move - next song. Easier than I thought, especially given the base already existing on the forum and the guidance for Puck. Thanks once again :)

About

Avatar for Gordon @Gordon started