![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This program aims to be an easy example for those starting, focusing in the analog input an digital output. The diagrams and wirings at http://mbed.org/users/Sergio/notebook/simple-voltage-indicator/#
Revision 0:acf4358ae130, committed 2010-09-07
- Comitter:
- Sergio
- Date:
- Tue Sep 07 23:18:25 2010 +0000
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r acf4358ae130 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 07 23:18:25 2010 +0000 @@ -0,0 +1,51 @@ +#include "mbed.h" + +AnalogIn input(p20); //the range of the analog input goes, from 0 V. to 3.3V. +// the actual value is represented as a float from 0 to 1. + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + + + +int main() { + + + float ain; //ain must be a float, for matching the input.read type. + + while (1) { + + ain=input.read(); + + if (ain<0.15) { //if analog input <0.15*3.3=0.45V + led1=0; + led2=0; + led3=0; + led4=0; + } else if ( ain>0.15 && ain<0.3) { // ain>0.45V and ain< 0.99V + led1=1; + led2=0; + led3=0; + led4=0; + } else if ( ain>0.3 && ain<0.6) { // ain>0.99V and ain<1.98V + led1=1; + led2=1; + led3=0; + led4=0; + } else if ( ain>0.6 && ain<0.91) { //ain>1.98 and ain>3.01V + led1=1; + led2=1; + led3=1; + led4=0; + } else { // more that 3 volts. + led1=1; + led2=2; + led3=1; + led4=1; + } + + + }//end while(1) +}//end main \ No newline at end of file
diff -r 000000000000 -r acf4358ae130 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Sep 07 23:18:25 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/74b8d43b5817