• Hi! It looks like you have to repeatedly 'poll' the module to ask it what keys are pressed, and then you get back a number where each bit represents a key.

    I2C1.setup({scl:B6,sda:B7});
    
    var lastKeysPressed = 0;
    var mpr = require("MPR121").connect(I2C1, {
       // device is ready
        setInterval(function() {
            var keys = mpr.touched();
            if (keys!=lastKeysPressed) {
              // for each key
              for (var i=0;i<12;i++) {
                var kbit = 1<<i;
                // if it is pressed now, but not before
                if ((keys&kbit) && !(lastKeysPressed&kbit))
                  console.log("Touched: " + i);
                // you can also check the opposite to see if it's released
              }
            }
             lastKeysPressed = keys;
        }, 100); // 100ms = 10 times a second
    });
    

    This isn't tested, but should work...

About

Avatar for Gordon @Gordon started