You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • There's also now support in the LL libs for the ADC and the RTC, so if you wanted to measure pulse length in a low-power way you could use the button length example:

    var ll = require("NRF52LL");
    // Source of events - the button
    // Note: this depends on the polarity of the physical button (this assumes that 0=pressed)
    var btnu = ll.gpiote(0, {type:"event",pin:BTN,lo2hi:1,hi2lo:0});­
    var btnd = ll.gpiote(1, {type:"event",pin:BTN,lo2hi:0,hi2lo:1});­
    // A place to recieve Tasks - the RTC
    var rtc = ll.rtc(2);
    poke32(rtc.prescaler, 0); // no prescaler, 32 kHz
    poke32(rtc.tStop, 1); // ensure RTC is stopped
    // Set up and enable PPI to start and stop the RTC
    ll.ppiEnable(0, btnd.eIn, rtc.tStart);
    ll.ppiEnable(1, btnu.eIn, rtc.tStop);
    // Every so often, check the RTC and report the result
    setInterval(function() {
      print(peek32(rtc.counter));
      poke32(rtc.tClear, 1);  
    }, 5000);
    

    Nothing stops you hooking that up with the 'button press counter' example so you can then get the average button press length with time_button_pressed / button_presses

About

Avatar for Gordon @Gordon started