having an external button control the media player.

Posted on
  • Hello Gordon,

    I have successfully set up the puck.js to control Music player via BLE as your cool project available at

    https://www.espruino.com/BLE+Music+Contr­ol

    I would like to now do the same thing with an external button attached to the puck.

    In another forum post, you said this was possible using the methods here:

    http://www.espruino.com/Button

    I see that I can connect the external switch between to io buttons (e.g. A6 and B1) and that I dont need to use an external resistor for this.

    I am unsure of the code to use. Do I just paste your two sets of code together (as I have done below - is it correct)? Or do I need to change some of the BTN lines?

    Thanks very much for your help...

    Gene


    digitalWrite(A6, 1);
    pinMode(B1, 'input_pulldown');
    
    setWatch(function(e) {
      console.log("Button pressed");
    }, BTN, { repeat: true, edge: 'rising', debounce: 50 });
    // you'll need to use  edge: 'falling' if you connected the button to 0v
    
    var controls = require("ble_hid_controls");
    NRF.setServices(undefined, { hid : controls.report });
    
    setWatch(function(e) {
      var len = e.time - e.lastTime;
      if (len > 0.3) {
        controls.next();
        digitalPulse(LED1,1,100);
      } else {
        controls.playpause();
        digitalPulse(LED2,1,100);
      }
    }, BTN, { edge:"falling",repeat:true,debounce:50})­;
    
  • Hi! Since you're using a Puck, the pin names are a bit different (starting with D... and not Ax/Bx/etc) but yes what you're suggesting is fine apart from that.

    I'd say just connect a button between maybe pin D1 and the 3v pin (this means you don't need digitalWrite(A6, 1);/similar because the pin is already at a voltage).

    Then it's just:

    pinMode(D1, 'input_pulldown');
    setWatch(function(e) {
      controls.playpause(); // or whatever else you want to do
    }, D1, { repeat: true, edge: 'rising', debounce: 50 });
    
    // your other HID code here...
    
  • Wow Gordon, thank you so much! I bought you a coffee with the donate button. Much appreciated.

  • Thank you! Did it work ok?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

having an external button control the media player.

Posted by Avatar for Gene @Gene

Actions