• You can use NRF.on('connect', ... and NRF.on('disconnect', ... events to turn on and off the sensor / sampling / updating.

    For example these two lines, turn on the magnetometer when connected, and turns it off when disconnected. The magnetometer event calls NRF.updateServices. So no magnetometer power consumption and updating of service data if nothing is connected:

      // on connect / disconnect blink the green / red LED turn on / off the magnetometer
      NRF.on('connect', function() {Puck.magOn(magRate); digitalPulse(LED2, 1, 100)})
      NRF.on('disconnect', function() {Puck.magOff(); digitalPulse(LED1, 1, 100)}) 
    

    Full code at https://github.com/AkosLukacs/PuckStreamĀ­ing

About

Avatar for AkosLukacs @AkosLukacs started