this is a ping-pang blinky in 4 LED.
Fork of mbed-os-example-mbed5-blinky by
main.cpp@14:c4162b826d08, 2016-10-20 (annotated)
- Committer:
- jasonjee
- Date:
- Thu Oct 20 14:08:21 2016 +0000
- Revision:
- 14:c4162b826d08
- Parent:
- 8:bb09890333fe
this is a ping-pang blinky.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
Jonathan Austin |
0:2757d7abb7d9 | 2 | |
Jonathan Austin |
0:2757d7abb7d9 | 3 | DigitalOut led1(LED1); |
jasonjee | 14:c4162b826d08 | 4 | DigitalOut led2(LED2); |
jasonjee | 14:c4162b826d08 | 5 | DigitalOut led3(LED3); |
jasonjee | 14:c4162b826d08 | 6 | DigitalOut led4(LED4); |
Jonathan Austin |
0:2757d7abb7d9 | 7 | |
Jonathan Austin |
1:846c97078558 | 8 | // main() runs in its own thread in the OS |
Jonathan Austin |
1:846c97078558 | 9 | // (note the calls to Thread::wait below for delays) |
Jonathan Austin |
0:2757d7abb7d9 | 10 | int main() { |
jasonjee | 14:c4162b826d08 | 11 | char a=1,b; |
Jonathan Austin |
0:2757d7abb7d9 | 12 | while (true) { |
jasonjee | 14:c4162b826d08 | 13 | led1 = !(a^1); |
jasonjee | 14:c4162b826d08 | 14 | led2 = !(a^2); |
jasonjee | 14:c4162b826d08 | 15 | led3 = !(a^4); |
jasonjee | 14:c4162b826d08 | 16 | led4 = !(a^8); |
jasonjee | 14:c4162b826d08 | 17 | if (led1) b=1; |
jasonjee | 14:c4162b826d08 | 18 | if (led4) b=0; |
jasonjee | 14:c4162b826d08 | 19 | if (b) a=a<<1; |
jasonjee | 14:c4162b826d08 | 20 | else a=a>>1; |
Jonathan Austin |
0:2757d7abb7d9 | 21 | Thread::wait(500); |
Jonathan Austin |
0:2757d7abb7d9 | 22 | } |
Jonathan Austin |
0:2757d7abb7d9 | 23 | } |
Jonathan Austin |
1:846c97078558 | 24 |