Skip to content

Instantly share code, notes, and snippets.

@menixator
Last active June 20, 2019 05:08
Show Gist options
  • Save menixator/3fb7ca2b1152f062ce7936acaa730dba to your computer and use it in GitHub Desktop.
Save menixator/3fb7ca2b1152f062ce7936acaa730dba to your computer and use it in GitHub Desktop.
#include "MicroBit.h"
MicroBit uBit;
bool started = false;
bool isSender = false;
int whatToSend = 0;
void onButtonA(MicroBitEvent event) {
if (started){
if (!isSender) return;
whatToSend = !whatToSend;
uBit.io.P0.setDigitalValue(whatToSend);
return;
}
isSender = true;
started = true;
}
void onButtonB(MicroBitEvent event) {
isSender = false;
started = true;
}
int main() {
// Initialise the micro:bit runtime.
uBit.init();
// Sleep if we haven't started.
while (!started){
uBit.sleep(100);
}
uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
while (1) {
if (!isSender) {
if (uBit.io.P0.getDigitalValue()){
uBit.display.print("1");
} else {
uBit.display.print("0");
}
uBit.sleep(20);
}
}
release_fiber();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment