IoT 2018
Dependencies: mbed
Fork of microbit_blinky by
Diff: main.cpp
- Revision:
- 1:0b38b848a5f0
- Parent:
- 0:025387782f3e
- Child:
- 2:83f7d8e01b11
--- a/main.cpp Wed Mar 02 18:01:16 2016 +0000 +++ b/main.cpp Thu Sep 20 09:17:38 2018 +0000 @@ -1,19 +1,35 @@ #include "mbed.h" -/* - * All the LEDs on the micro:bit are part of the LED Matrix, - * In order to get simple blinking behaviour, we set column 0 - * to be permanently at ground. If you want to use the LEDs as - * a screen, there is a display driver in the micro:bit 'DAL', - */ -DigitalOut col0(P0_4, 0); + +// Button A is on P0 bit 17 +// Pin labelled "0" on edge connector is in fact connected to P0_3 +volatile uint32_t * P0OUT = (uint32_t *)0x50000504; +volatile uint32_t * P0DIR = (uint32_t *)0x50000514; +volatile uint32_t * P0IN = (uint32_t *)0x50000510; +volatile uint32_t * P0CONF = (uint32_t *)(0x50000700); -DigitalOut myled(P0_13); - +void dly(volatile uint32_t len) +{ + // "volatile" modifier is necessary here + // to prevent the compiler from optimizing + // this software delay to nothing + while(len--); +} +int ButtonAPressed() +{ + // Button A pulls down so bit is zero when pressed. + if ((*P0IN & (1 << 17))==0) + return 1; + else + return 0; +} int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + + *P0DIR = (1 << 3); + P0CONF[17] = 0; // On power up, input buffer is not connected so must do this + while(1) { + if (ButtonAPressed()) + *P0OUT = (1 << 3); + else + *P0OUT = 0; } }