mr happy
/
flashing_leds
Reads the voltage from Pin18 (out) based on the output from Pin(20) i.e a self checking voltmeter.
main.cpp@0:7c659fdad918, 2011-02-04 (annotated)
- Committer:
- mrhappy
- Date:
- Fri Feb 04 22:36:45 2011 +0000
- Revision:
- 0:7c659fdad918
- Child:
- 1:a4c99d145ce3
V0.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mrhappy | 0:7c659fdad918 | 1 | #include "mbed.h" |
mrhappy | 0:7c659fdad918 | 2 | |
mrhappy | 0:7c659fdad918 | 3 | AnalogIn ain(p20); |
mrhappy | 0:7c659fdad918 | 4 | DigitalOut led1(LED1); |
mrhappy | 0:7c659fdad918 | 5 | DigitalOut led2(LED2); |
mrhappy | 0:7c659fdad918 | 6 | DigitalOut led3(LED3); |
mrhappy | 0:7c659fdad918 | 7 | DigitalOut led4(LED4); |
mrhappy | 0:7c659fdad918 | 8 | |
mrhappy | 0:7c659fdad918 | 9 | // use pin 20 and GND to display a binary read out on the lights |
mrhappy | 0:7c659fdad918 | 10 | // of the voltage across the pins. |
mrhappy | 0:7c659fdad918 | 11 | // did not validate this in anyway. |
mrhappy | 0:7c659fdad918 | 12 | // mrhappy |
mrhappy | 0:7c659fdad918 | 13 | |
mrhappy | 0:7c659fdad918 | 14 | void bindisplay(int i){ |
mrhappy | 0:7c659fdad918 | 15 | |
mrhappy | 0:7c659fdad918 | 16 | // based on Kohei Matsumura code. |
mrhappy | 0:7c659fdad918 | 17 | wait(0.2); |
mrhappy | 0:7c659fdad918 | 18 | led1 = i & 0x01; |
mrhappy | 0:7c659fdad918 | 19 | led2 = i>>1 & 0x01; |
mrhappy | 0:7c659fdad918 | 20 | led3 = i>>2 & 0x01; |
mrhappy | 0:7c659fdad918 | 21 | led4 = i>>3 & 0x01; |
mrhappy | 0:7c659fdad918 | 22 | |
mrhappy | 0:7c659fdad918 | 23 | } |
mrhappy | 0:7c659fdad918 | 24 | |
mrhappy | 0:7c659fdad918 | 25 | int main() { |
mrhappy | 0:7c659fdad918 | 26 | |
mrhappy | 0:7c659fdad918 | 27 | while (1){ |
mrhappy | 0:7c659fdad918 | 28 | |
mrhappy | 0:7c659fdad918 | 29 | bindisplay( ain * 0x0f ); |
mrhappy | 0:7c659fdad918 | 30 | |
mrhappy | 0:7c659fdad918 | 31 | } |
mrhappy | 0:7c659fdad918 | 32 | } |