Counts to 15 and back to 0 using the 4 LEDs
Dependencies: C12832_lcd LM75B mbed
Fork of app-board-LM75B by
main.cpp@4:18680ed950a8, 2014-04-29 (annotated)
- Committer:
- wren301
- Date:
- Tue Apr 29 01:49:55 2014 +0000
- Revision:
- 4:18680ed950a8
- Parent:
- 3:4d612f16ad84
Count to 15 in Binary with LEDs, complete and tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:ce7a8546502b | 1 | #include "mbed.h" |
okano | 0:ce7a8546502b | 2 | |
wren301 | 4:18680ed950a8 | 3 | DigitalOut blue3(LED1); |
wren301 | 4:18680ed950a8 | 4 | DigitalOut blue2(LED2); |
wren301 | 4:18680ed950a8 | 5 | DigitalOut blue1(LED3); |
wren301 | 4:18680ed950a8 | 6 | DigitalOut blue0(LED4); |
okano | 0:ce7a8546502b | 7 | |
chris | 2:9e757151de9b | 8 | int main () |
okano | 0:ce7a8546502b | 9 | { |
wren301 | 4:18680ed950a8 | 10 | int numToDisplay = 0; |
wren301 | 4:18680ed950a8 | 11 | int highNum = 15; |
wren301 | 4:18680ed950a8 | 12 | |
wren301 | 4:18680ed950a8 | 13 | if(highNum > 15) { |
wren301 | 4:18680ed950a8 | 14 | error("Number too high to count to!"); |
wren301 | 4:18680ed950a8 | 15 | } |
chris | 2:9e757151de9b | 16 | while (1) { |
wren301 | 4:18680ed950a8 | 17 | for (int i = 0; i < 2*highNum; i++) { |
wren301 | 4:18680ed950a8 | 18 | numToDisplay = i; |
wren301 | 4:18680ed950a8 | 19 | if (i > highNum) { |
wren301 | 4:18680ed950a8 | 20 | numToDisplay = 2*highNum - i; |
wren301 | 4:18680ed950a8 | 21 | } |
wren301 | 4:18680ed950a8 | 22 | |
wren301 | 4:18680ed950a8 | 23 | blue3 = (numToDisplay & 8); |
wren301 | 4:18680ed950a8 | 24 | blue2 = (numToDisplay & 4); |
wren301 | 4:18680ed950a8 | 25 | blue1 = (numToDisplay & 2); |
wren301 | 4:18680ed950a8 | 26 | blue0 = (numToDisplay & 1); |
wren301 | 4:18680ed950a8 | 27 | wait(1.0); |
wren301 | 4:18680ed950a8 | 28 | } |
chris | 2:9e757151de9b | 29 | } |
okano | 0:ce7a8546502b | 30 | } |