read voltage value and show with 7 segments LED.
Fork of Nucleo_read_analog_value by
main.cpp@0:b30041f75f46, 2015-08-23 (annotated)
- Committer:
- soulx
- Date:
- Sun Aug 23 13:04:42 2015 +0000
- Revision:
- 0:b30041f75f46
- Child:
- 1:5dd840359117
Lab2 analog read
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soulx | 0:b30041f75f46 | 1 | #include "mbed.h" |
soulx | 0:b30041f75f46 | 2 | |
soulx | 0:b30041f75f46 | 3 | AnalogIn analog_value(A0); |
soulx | 0:b30041f75f46 | 4 | |
soulx | 0:b30041f75f46 | 5 | DigitalOut led(LED1); |
soulx | 0:b30041f75f46 | 6 | |
soulx | 0:b30041f75f46 | 7 | int main() { |
soulx | 0:b30041f75f46 | 8 | float meas; |
soulx | 0:b30041f75f46 | 9 | |
soulx | 0:b30041f75f46 | 10 | while(1) { |
soulx | 0:b30041f75f46 | 11 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
soulx | 0:b30041f75f46 | 12 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
soulx | 0:b30041f75f46 | 13 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
soulx | 0:b30041f75f46 | 14 | led = 1; |
soulx | 0:b30041f75f46 | 15 | } |
soulx | 0:b30041f75f46 | 16 | else { |
soulx | 0:b30041f75f46 | 17 | led = 0; |
soulx | 0:b30041f75f46 | 18 | } |
soulx | 0:b30041f75f46 | 19 | wait(0.2); // 200 ms |
soulx | 0:b30041f75f46 | 20 | } |
soulx | 0:b30041f75f46 | 21 | } |