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 http://www.espruino.com/Reference 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");
digitalWrite(PINDRV,0);
digitalRead([PIN1,PIN2]);
// 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
poke32(tmr.tClear,1);
poke32(tmr.tStart,1);
return { read : function() {
return [ peek32(tmr.cc[1]), peek32(tmr.cc[2]) ];
} };
}
var cap = capSense2(D25, D31, D5);
setInterval(function() {
console.log(cap.read());
},500);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The Puck's capsense code is here: https://github.com/espruino/Espruino/blob/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 http://www.espruino.com/Reference 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: