diff --git a/source/main.cpp b/source/main.cpp index 0c72d35174d388cf190e0fafb84c625fad7b5da0..d77d9ca116d83a8ae28bde15538ff9015eef7aed 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -17,36 +17,38 @@ #include "MicroBit.h" -MicroBit micro_bit; +MicroBit ubit; class EventThingy { public: + EventThingy() { + ubit.messageBus.listen( + MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, this, &EventThingy::event_handler_a + ); + + ubit.messageBus.listen( + MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, this, &EventThingy::event_handler_b + ); + } + void event_handler_a(MicroBitEvent) { - micro_bit.display.image.setPixelValue(0, 2, 1); + ubit.display.image.setPixelValue(2, 2, 1); } void event_handler_b(MicroBitEvent) { - micro_bit.display.image.setPixelValue(4, 2, 1); + ubit.display.image.setPixelValue(2, 2, 0); } }; -EventThingy eventer; - int main() { // Initialise the micro:bit runtime. - micro_bit.init(); - - micro_bit.messageBus.listen( - MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, &eventer, &EventThingy::event_handler_a - ); + ubit.init(); - micro_bit.messageBus.listen( - MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, &eventer, &EventThingy::event_handler_b - ); + EventThingy eventer; while (true) { - micro_bit.sleep(10); // 10ms sleep, or 100Hz tick rate + ubit.sleep(10); // 10ms sleep, or 100Hz tick rate } // TODO: potentially remove this call, if clarified that it is not required.