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@1:a4c99d145ce3, 2011-02-04 (annotated)
- Committer:
- mrhappy
- Date:
- Fri Feb 04 23:08:04 2011 +0000
- Revision:
- 1:a4c99d145ce3
- Parent:
- 0:7c659fdad918
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 | 1:a4c99d145ce3 | 4 | AnalogOut aout(p18); |
mrhappy | 1:a4c99d145ce3 | 5 | |
mrhappy | 0:7c659fdad918 | 6 | DigitalOut led1(LED1); |
mrhappy | 0:7c659fdad918 | 7 | DigitalOut led2(LED2); |
mrhappy | 0:7c659fdad918 | 8 | DigitalOut led3(LED3); |
mrhappy | 0:7c659fdad918 | 9 | DigitalOut led4(LED4); |
mrhappy | 0:7c659fdad918 | 10 | |
mrhappy | 0:7c659fdad918 | 11 | // use pin 20 and GND to display a binary read out on the lights |
mrhappy | 0:7c659fdad918 | 12 | // of the voltage across the pins. |
mrhappy | 0:7c659fdad918 | 13 | // did not validate this in anyway. |
mrhappy | 0:7c659fdad918 | 14 | // mrhappy |
mrhappy | 0:7c659fdad918 | 15 | |
mrhappy | 0:7c659fdad918 | 16 | void bindisplay(int i){ |
mrhappy | 0:7c659fdad918 | 17 | |
mrhappy | 0:7c659fdad918 | 18 | // based on Kohei Matsumura code. |
mrhappy | 1:a4c99d145ce3 | 19 | wait(0.5); |
mrhappy | 0:7c659fdad918 | 20 | led1 = i & 0x01; |
mrhappy | 0:7c659fdad918 | 21 | led2 = i>>1 & 0x01; |
mrhappy | 0:7c659fdad918 | 22 | led3 = i>>2 & 0x01; |
mrhappy | 0:7c659fdad918 | 23 | led4 = i>>3 & 0x01; |
mrhappy | 0:7c659fdad918 | 24 | |
mrhappy | 0:7c659fdad918 | 25 | } |
mrhappy | 0:7c659fdad918 | 26 | |
mrhappy | 0:7c659fdad918 | 27 | int main() { |
mrhappy | 0:7c659fdad918 | 28 | |
mrhappy | 1:a4c99d145ce3 | 29 | float vout = 0; |
mrhappy | 1:a4c99d145ce3 | 30 | |
mrhappy | 1:a4c99d145ce3 | 31 | while(1) |
mrhappy | 1:a4c99d145ce3 | 32 | { |
mrhappy | 1:a4c99d145ce3 | 33 | bindisplay( ain * 0xffff ); |
mrhappy | 0:7c659fdad918 | 34 | |
mrhappy | 1:a4c99d145ce3 | 35 | vout += 0.1; |
mrhappy | 1:a4c99d145ce3 | 36 | aout = vout; |
mrhappy | 1:a4c99d145ce3 | 37 | |
mrhappy | 1:a4c99d145ce3 | 38 | if (vout > 1) vout = 0; |
mrhappy | 0:7c659fdad918 | 39 | } |
mrhappy | 0:7c659fdad918 | 40 | } |