Lab2
Dependencies: mbed
Revision 2:3ff3ecfd9c70, committed 2015-10-13
- Comitter:
- Pitiwut
- Date:
- Tue Oct 13 08:20:27 2015 +0000
- Parent:
- 1:f8fedb15be2e
- Commit message:
- Recommit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f8fedb15be2e -r 3ff3ecfd9c70 main.cpp --- a/main.cpp Tue Oct 13 07:56:51 2015 +0000 +++ b/main.cpp Tue Oct 13 08:20:27 2015 +0000 @@ -2,114 +2,20 @@ AnalogIn analog_value(A0); -DigitalOut led1(D13); -DigitalOut led2(D12); -DigitalOut led3(D11); -DigitalOut led4(D10); -DigitalOut led5(D9); -DigitalOut led6(D8); -DigitalOut led7(D7); -DigitalOut led8(D6); - +DigitalOut led(LED1); + int main() { - double meas; + float meas; while(1) { meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) - 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; + 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; } - 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; + else { + led = 0; } - 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; - } - + wait(0.2); // 200 ms } -} +} \ No newline at end of file