read voltage value and show with 7 segments LED.
Fork of Nucleo_read_analog_value by
Revision 1:5dd840359117, committed 2015-11-16
- Comitter:
- 57340500039
- Date:
- Mon Nov 16 14:03:41 2015 +0000
- Parent:
- 0:b30041f75f46
- Commit message:
- read voltage and show it with 7 segments LED.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b30041f75f46 -r 5dd840359117 main.cpp --- a/main.cpp Sun Aug 23 13:04:42 2015 +0000 +++ b/main.cpp Mon Nov 16 14:03:41 2015 +0000 @@ -1,20 +1,42 @@ #include "mbed.h" +#include "math.h" AnalogIn analog_value(A0); -DigitalOut led(LED1); +DigitalOut led1(D2); +DigitalOut led2(D3); +DigitalOut led3(D4); +DigitalOut led4(D5); +DigitalOut led5(D6); +DigitalOut led6(D7); +int i=0,vaule1,vaule10; +//DigitalOut led[6] = {led1,led2,led3,led4,led5,led6}; int main() { float meas; while(1) { meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) - meas = meas * 3300; // Change the value to be in the 0 to 3300 range - if (meas > 2000) { // If the value is greater than 2V then switch the LED on - led = 1; + meas = meas * 33.0; // Change the value to be in the 0 to 33 range + vaule10 = floor(meas/10.0); + vaule1 = floor((meas - (float) vaule10*10)); + switch(vaule10){ + case 0: led5 = 0; led6 = 0; break; + case 1: led5 = 1; led6 = 0; break; + case 2: led5 = 0; led6 = 1; break; + case 3: led5 = 1; led6 = 1; break; } - else { - led = 0; + switch(vaule1){ + case 0: led1 = 0; led2 = 0; led3 = 0; led4 = 0; break; + case 1: led1 = 1; led2 = 0; led3 = 0; led4 = 0; break; + case 2: led1 = 0; led2 = 1; led3 = 0; led4 = 0; break; + case 3: led1 = 1; led2 = 1; led3 = 0; led4 = 0; break; + case 4: led1 = 0; led2 = 0; led3 = 1; led4 = 0; break; + case 5: led1 = 1; led2 = 0; led3 = 1; led4 = 0; break; + case 6: led1 = 0; led2 = 1; led3 = 1; led4 = 0; break; + case 7: led1 = 1; led2 = 1; led3 = 1; led4 = 0; break; + case 8: led1 = 0; led2 = 0; led3 = 0; led4 = 1; break; + case 9: led1 = 1; led2 = 0; led3 = 0; led4 = 1; break; } wait(0.2); // 200 ms }