This is a souped up version of the basic mbed blinky, as a 2nd stepping stone up from the basic blinky and also because the documentation doesn't seem to really be that complete.
Fork of mbed_quadBlinky by
main.cpp@0:efe13d6feef8, 2017-10-03 (annotated)
- Committer:
- shutay
- Date:
- Tue Oct 03 16:53:41 2017 +0000
- Revision:
- 0:efe13d6feef8
- Child:
- 1:f4e48249b980
Souped up version of the basic blinky.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shutay | 0:efe13d6feef8 | 1 | #include "mbed.h" |
shutay | 0:efe13d6feef8 | 2 | |
shutay | 0:efe13d6feef8 | 3 | Serial pc(USBTX, USBRX); |
shutay | 0:efe13d6feef8 | 4 | |
shutay | 0:efe13d6feef8 | 5 | DigitalOut led1(LED1); |
shutay | 0:efe13d6feef8 | 6 | DigitalOut led2(LED2); |
shutay | 0:efe13d6feef8 | 7 | DigitalOut led3(LED3); |
shutay | 0:efe13d6feef8 | 8 | DigitalOut led4(LED4); |
shutay | 0:efe13d6feef8 | 9 | |
shutay | 0:efe13d6feef8 | 10 | void initialise() |
shutay | 0:efe13d6feef8 | 11 | { |
shutay | 0:efe13d6feef8 | 12 | // Baud rate not required over USB. |
shutay | 0:efe13d6feef8 | 13 | led1 = 1; |
shutay | 0:efe13d6feef8 | 14 | led2 = 1; |
shutay | 0:efe13d6feef8 | 15 | led3 = 1; |
shutay | 0:efe13d6feef8 | 16 | led4 = 1; |
shutay | 0:efe13d6feef8 | 17 | wait(1.0f); |
shutay | 0:efe13d6feef8 | 18 | //*==========================================* |
shutay | 0:efe13d6feef8 | 19 | // Do initialisation here |
shutay | 0:efe13d6feef8 | 20 | //*==========================================* |
shutay | 0:efe13d6feef8 | 21 | |
shutay | 0:efe13d6feef8 | 22 | //*==========================================* |
shutay | 0:efe13d6feef8 | 23 | led1 = 0; |
shutay | 0:efe13d6feef8 | 24 | led2 = 0; |
shutay | 0:efe13d6feef8 | 25 | led3 = 0; |
shutay | 0:efe13d6feef8 | 26 | led4 = 0; |
shutay | 0:efe13d6feef8 | 27 | wait(1.0f); |
shutay | 0:efe13d6feef8 | 28 | } |
shutay | 0:efe13d6feef8 | 29 | |
shutay | 0:efe13d6feef8 | 30 | void updateLEDs(int val) |
shutay | 0:efe13d6feef8 | 31 | { |
shutay | 0:efe13d6feef8 | 32 | led1 = val & 0x01; |
shutay | 0:efe13d6feef8 | 33 | led2 = (val & 0x02) >> 1; |
shutay | 0:efe13d6feef8 | 34 | led3 = (val & 0x04) >> 2; |
shutay | 0:efe13d6feef8 | 35 | led4 = (val & 0x08) >> 3; |
shutay | 0:efe13d6feef8 | 36 | } |
shutay | 0:efe13d6feef8 | 37 | |
shutay | 0:efe13d6feef8 | 38 | void advanceLEDs(int *val) |
shutay | 0:efe13d6feef8 | 39 | { |
shutay | 0:efe13d6feef8 | 40 | *val = *val << 1; |
shutay | 0:efe13d6feef8 | 41 | if(*val>0x08) *val = 1; |
shutay | 0:efe13d6feef8 | 42 | } |
shutay | 0:efe13d6feef8 | 43 | |
shutay | 0:efe13d6feef8 | 44 | int main() |
shutay | 0:efe13d6feef8 | 45 | { |
shutay | 0:efe13d6feef8 | 46 | initialise(); |
shutay | 0:efe13d6feef8 | 47 | |
shutay | 0:efe13d6feef8 | 48 | int i = 1; |
shutay | 0:efe13d6feef8 | 49 | while(1) |
shutay | 0:efe13d6feef8 | 50 | { |
shutay | 0:efe13d6feef8 | 51 | updateLEDs(i); |
shutay | 0:efe13d6feef8 | 52 | advanceLEDs(&i); |
shutay | 0:efe13d6feef8 | 53 | wait(0.5f); |
shutay | 0:efe13d6feef8 | 54 | } |
shutay | 0:efe13d6feef8 | 55 | } |