Last active
April 4, 2020 12:16
-
-
Save reynish/039f22477513cbe516e7f5e8bd78b33a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Have a service to show temperature and battery level | |
// This is only visible when you are connecting to the Puck | |
var currentTemperature=E.getTemperature().toFixed(2)*100; | |
console.log("Temp: "+currentTemperature); | |
NRF.setServices({ | |
"12411007-877b-4b6e-1d8a036a956a" : { // Health Thermometer | |
"7e3defd9-1426-068f-d744-fa70603d83ac": { // Temperature | |
readable: true, | |
notify: true, | |
value : [ currentTemperature % 256, currentTemperature / 256 ] | |
} | |
}, | |
0x180f : { // Battery Level | |
0x2a19 : { // Percentage | |
readable : true, | |
notify: true, | |
value: [ Puck.getBatteryPercentage() ], | |
} | |
} | |
}); | |
// Updating the temperature | |
setWatch(function() { | |
currentTemperature += 1; // For debugging: increase temp by 0.01 degree per update | |
console.log(currentTemperature); | |
NRF.updateServices({ | |
"12411007-877b-4b6e-1d8a036a956a" : { | |
"7e3defd9-1426-068f-d744-fa70603d83ac" : { | |
value : [ currentTemperature % 256, currentTemperature / 256 ], | |
notify: true | |
} | |
} | |
}); | |
}, BTN, {edge:"rising", debounce:50, repeat:true}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment