Newbie to Puck.js - Movement to IFTTT

Posted on
  • Hey community. Quick question for you. I just received a puck.js in the mail, and I've been playing around with it, but I can't figure something out.

    I've done the "Bluetooth LE and If This Then That" tutorial, where if you press a button, it triggers your IFTTT applet, but I'm trying to code if the puck moves instead of pushing the button.

    Can anyone help me out? Thank you!

  • In http://www.espruino.com/BLE+IFTTT there's this code, which is what gets run on the Puck:

    connection.write("\x10setWatch(function(­){Bluetooth.println('Pressed');},BTN,{re­peat:true,debounce:50,edge:'rising'});\n­",
    

    The gotcha you have is that the code on http://www.espruino.com/Puck.js#accelero­meter-gyro uses a library, which won't get uploaded if you copy/paste that code. So what I'd say is, open the Web IDE and upload this code to the Puck (to Flash):

    require("puckjsv2-accel-movement").on();­
    var idleTimeout;
    Puck.on('accel',function(a) {
      LED.set();
      if (idleTimeout) clearTimeout(idleTimeout);
      else Bluetooth.println("Pressed");
      idleTimeout = setTimeout(function() {
        idleTimeout = undefined;
        LED.reset();
      },500);  
    });
    

    And then delete all this code from the IFTTT example:

    connection.write("\x10reset();\n", function() {
              // Wait for it to reset itself
              setTimeout(function() {
                // Now tell it to write data on the current light level to Bluetooth 10 times a second
                connection.write("\x10setWatch(function(­){Bluetooth.println('Pressed');},BTN,{re­peat:true,debounce:50,edge:'rising'});\n­",
                  function() { log("Ready!"); });
              }, 1500);
            });
    

    You don't need any of that code any more because you've just manually loaded the code onto the Puck. Now you should be sorted :)

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

Newbie to Puck.js - Movement to IFTTT

Posted by Avatar for JasonD @JasonD

Actions