Skip to content

Instantly share code, notes, and snippets.

@jaustin
Forked from khanning/lightleveltest.cpp
Last active May 15, 2019 16:04
Show Gist options
  • Save jaustin/b670a3cd5bd2d159301a9552020307e9 to your computer and use it in GitHub Desktop.
Save jaustin/b670a3cd5bd2d159301a9552020307e9 to your computer and use it in GitHub Desktop.
//Kregg's light sensor failure example
//https://gist.github.com/khanning/19753c1a0f978117b992c60668d09d1c
// build as main.cpp in microbit-samples
#include "MicroBit.h"
MicroBit uBit;
uint8_t lightLevel;
void lightLevelReady(MicroBitEvent) {
lightLevel = uBit.display.readLightLevel();
uBit.serial.send(lightLevel);
uBit.serial.send("\r\n");
}
int main() {
uBit.init();
uBit.messageBus.listen(MICROBIT_ID_DISPLAY, MICROBIT_DISPLAY_EVT_LIGHT_SENSE, lightLevelReady);
uBit.display.readLightLevel();
while (1) {
fiber_sleep(20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment