IoT 2018

Dependencies:   mbed

Fork of microbit_blinky by BBC

Committer:
f3d
Date:
Thu Sep 20 10:58:30 2018 +0000
Revision:
2:83f7d8e01b11
Parent:
1:0b38b848a5f0
Revised version of code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonnyA 0:025387782f3e 1 #include "mbed.h"
f3d 1:0b38b848a5f0 2
f3d 1:0b38b848a5f0 3 // Button A is on P0 bit 17
f3d 1:0b38b848a5f0 4 // Pin labelled "0" on edge connector is in fact connected to P0_3
f3d 1:0b38b848a5f0 5 volatile uint32_t * P0OUT = (uint32_t *)0x50000504;
f3d 1:0b38b848a5f0 6 volatile uint32_t * P0DIR = (uint32_t *)0x50000514;
f3d 1:0b38b848a5f0 7 void dly(volatile uint32_t len)
f3d 1:0b38b848a5f0 8 {
f3d 1:0b38b848a5f0 9 // "volatile" modifier is necessary here
f3d 1:0b38b848a5f0 10 // to prevent the compiler from optimizing
f3d 1:0b38b848a5f0 11 // this software delay to nothing
f3d 1:0b38b848a5f0 12 while(len--);
f3d 1:0b38b848a5f0 13 }
JonnyA 0:025387782f3e 14 int main() {
f3d 1:0b38b848a5f0 15
f3d 2:83f7d8e01b11 16 *P0DIR = (1 << 3); // Make P0 Bit 3 (labelled 0 on breakout board) an output
f3d 2:83f7d8e01b11 17 while(1) {
f3d 2:83f7d8e01b11 18 *P0OUT = (1 << 3); // Make P0 Bit 3 a '1' (turns on the LED)
f3d 2:83f7d8e01b11 19 dly(1000000); // wait a while
f3d 2:83f7d8e01b11 20 *P0OUT = 0; // LED off
f3d 2:83f7d8e01b11 21 dly(1000000); // Wait a while
JonnyA 0:025387782f3e 22 }
JonnyA 0:025387782f3e 23 }