tedsat
Dependencies: mbed
Fork of Nucleo_read_analog_value by
Diff: main.cpp
- Revision:
- 1:f8fedb15be2e
- Parent:
- 0:b30041f75f46
diff -r b30041f75f46 -r f8fedb15be2e main.cpp --- a/main.cpp Sun Aug 23 13:04:42 2015 +0000 +++ b/main.cpp Tue Oct 13 07:56:51 2015 +0000 @@ -2,20 +2,114 @@ AnalogIn analog_value(A0); -DigitalOut led(LED1); +DigitalOut led1(D13); +DigitalOut led2(D12); +DigitalOut led3(D11); +DigitalOut led4(D10); +DigitalOut led5(D9); +DigitalOut led6(D8); +DigitalOut led7(D7); +DigitalOut led8(D6); int main() { - float meas; + double 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*3.3; + if (meas >= 0 && meas < 0.17) + { led1 = 0; + led2 = 0; + led3 = 0; + led4 = 0; + led5 = 0; + led6 = 0; + led7 = 0; + led8 = 0; + } + + else if (meas > 0.17 && meas <= 0.23571429) + { // If the value is greater than 2V then switch the LED on + led1 = 1; + led2 = 0; + led3 = 0; + led4 = 0; + led5 = 0; + led6 = 0; + led7 = 0; + led8 = 0; + } + else if (meas > 0.23571429 && meas <= 0.70714286) + { led1 = 1; + led2 = 1; + led3 = 0; + led4 = 0; + led5 = 0; + led6 = 0; + led7 = 0; + led8 = 0; + } + else if (meas > 0.70714286 && meas <= 1.17857143) + { led1 = 1; + led2 = 1; + led3 = 1; + led4 = 0; + led5 = 0; + led6 = 0; + led7 = 0; + led8 = 0; } - else { - led = 0; + else if (meas > 1.17857143 && meas <= 1.65) + { led1 = 1; + led2 = 1; + led3 = 1; + led4 = 1; + led5 = 0; + led6 = 0; + led7 = 0; + led8 = 0; + } + else if (meas > 1.65 && meas <= 2.12142857) + { led1 = 1; + led2 = 1; + led3 = 1; + led4 = 1; + led5 = 1; + led6 = 0; + led7 = 0; + led8 = 0; } - wait(0.2); // 200 ms + else if (meas > 2.12142857 && meas <= 2.59285714) + { led1 = 1; + led2 = 1; + led3 = 1; + led4 = 1; + led5 = 1; + led6 = 1; + led7 = 0; + led8 = 0; + } + else if (meas > 2.59285714 && meas <= 3.06428571) + { led1 = 1; + led2 = 1; + led3 = 1; + led4 = 1; + led5 = 1; + led6 = 1; + led7 = 1; + led8 = 0; + + } + else if (meas > 3.06428571 && meas <= 3.53571428) + { led1 = 1; + led2 = 1; + led3 = 1; + led4 = 1; + led5 = 1; + led6 = 1; + led7 = 1; + led8 = 1; + } + } }