Can my puck interrupt on both BTN and TILT?

Posted on
  • Looking at the tilt library it seems to be using INT1.

    The setWatch(button) isn't clear on which interrupt it is using.

    Each of these two separate tests work independently but when I combine them they must conflict.

    var pressCount = 0;
    var tiltCount = 0;
    var batt = 0;
    var redLEDOn = false;
    var greenLEDOn = false;
    var blueLEDOn = false;
    function swapBlue() {
      blueLEDOn = !blueLEDOn;
    function swapGreen() {
      greenLEDOn = !greenLEDOn;
    # Tilt detection works by itself, fails when combined with Button watching.
    Puck.on('accel',function() {
      batt = Puck.getBatteryPercentage();
        0x1821 : [tiltCount],
        0x180f : batt,
    # Button watching works by itself but fails when combined with tilt detection.
    setWatch(function() {
      batt = Puck.getBatteryPercentage();
        0x1812 : [pressCount],
        0x180f : batt,
    }, BTN, { edge:"rising", repeat:true, debounce:50 });
  • The two things will work fine together - Puck.js has a bunch of different interrupt sources and chooses them such that they don't conflict.

    However probably what you're hitting is that setAdvertising isn't additive - so when you call the button one you'll end up removing the 0x1821 service that the tilt listener added?

    Easiest thing to do is to create one function called updateAdvertising that sets everything, and then call that whenever something changes.

    Also just FYI, but swapBlue/etc can be replaced with LED3.toggle() if you want to swap the LED state

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

Can my puck interrupt on both BTN and TILT?

Posted by Avatar for HeneryH_(Henery_Hawk) @HeneryH_(Henery_Hawk)