You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • The Puck's capsense code is here:­b/master/targets/nrf5x/nrf5x_utils.c#L61­

    But I actually don't use the hardware variant - I use the simple software one below it.

    Just FYI -if you want to see how something is done, look in and after the title of a function there's a => symbol - click on that and you'll go right to GitHub where it's defined.

    Here's some code you can use. I'll update the NRF52LL page:

    function capSense2(PINDRV, PIN1, PIN2) {
      var ll = require("NRF52LL");
      // create a 'toggle' task for output
      var t0 = ll.gpiote(0, {type:"task",pin:PINDRV,lo2hi:1,hi2lo:1,­initialState:0});
      // two input tasks, one for each cap sense input
      var e1 = ll.gpiote(1, {type:"event",pin:PIN1,lo2hi:1,hi2lo:0})­;
      var e2 = ll.gpiote(2, {type:"event",pin:PIN2,lo2hi:1,hi2lo:0})­;
      // create a timer that counts up to 1000 and back at full speed
      var tmr = ll.timer(3,{cc:[1000],cc0clear:1});
      // use a PPI to trigger toggle events
      ll.ppiEnable(0, tmr.eCompare[0], t0.tOut);
      // use 2 more to 'capture' the current timer value when a pin changes from low to high
      ll.ppiEnable(1, e1.eIn, tmr.tCapture[1]);
      ll.ppiEnable(2, e2.eIn, tmr.tCapture[2]);
      // Manually trigger a task to clear and start the timer
      return { read : function() {
        return [ peek32([1]), peek32([2]) ];
      } };
    var cap = capSense2(D25, D31, D5);
    setInterval(function() {

Avatar for Gordon @Gordon started