This simple program displays either "A" or "B" on LED matrix when you press A/B button built-on micro:bit and any compatible devices (such as chibi:bit)
Revision 0:520a08b6329a, committed 2016-08-12
- Comitter:
- iwaita2ya
- Date:
- Fri Aug 12 04:17:51 2016 +0000
- Commit message:
- 1st commit.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
microbit.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 520a08b6329a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Aug 12 04:17:51 2016 +0000 @@ -0,0 +1,46 @@ +/****************************************************************************** +main.cpp + +Tatsuya Iwai @ greysound.com +Original Creation Date: Aug 12, 2016 +https://github.com/sparkfun/LSM9DS1_Breakout + +This simple program tests built-in "A" and "B" button on micro:bit or any +compatible devices (such as "chibi:bit") shows button label on LED matrix +when either button is pressed. + +Distributed as-is; no warranty is given. +******************************************************************************/ + +#include "MicroBit.h" + +// Objects -------------------------------------------------------------------- +MicroBitMessageBus bus; +MicroBitButton buttonA(MICROBIT_PIN_BUTTON_A, MICROBIT_ID_BUTTON_A); +MicroBitButton buttonB(MICROBIT_PIN_BUTTON_B, MICROBIT_ID_BUTTON_B); +MicroBitDisplay display; + +// Function prototypes -------------------------------------------------------- +void onPressed(MicroBitEvent e); + +// Main ---------------------------------------------------------------------- +int main() +{ + scheduler_init(bus); + + bus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onPressed); + bus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onPressed); + + while(1) + fiber_sleep(1000); +} + +// Functions ------------------------------------------------------------------ +void onPressed(MicroBitEvent e) +{ + if (e.source == MICROBIT_ID_BUTTON_A) + display.scroll("A"); + + if (e.source == MICROBIT_ID_BUTTON_B) + display.scroll("B"); +} \ No newline at end of file
diff -r 000000000000 -r 520a08b6329a microbit.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/microbit.lib Fri Aug 12 04:17:51 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Lancaster-University/code/microbit/#4b89e7e3494f