![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TRR2018 omar
Fork of biniou by
main.cpp@0:3d0394820179, 2018-08-22 (annotated)
- Committer:
- ohlimi2
- Date:
- Wed Aug 22 16:12:16 2018 +0000
- Revision:
- 0:3d0394820179
- Child:
- 1:abed67ad1d03
first commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ohlimi2 | 0:3d0394820179 | 1 | #include "mbed.h" |
ohlimi2 | 0:3d0394820179 | 2 | |
ohlimi2 | 0:3d0394820179 | 3 | AnalogIn analog_value(A0); |
ohlimi2 | 0:3d0394820179 | 4 | |
ohlimi2 | 0:3d0394820179 | 5 | DigitalOut led(LED1); |
ohlimi2 | 0:3d0394820179 | 6 | |
ohlimi2 | 0:3d0394820179 | 7 | int main() { |
ohlimi2 | 0:3d0394820179 | 8 | float meas; |
ohlimi2 | 0:3d0394820179 | 9 | |
ohlimi2 | 0:3d0394820179 | 10 | printf("\nAnalogIn example\n"); |
ohlimi2 | 0:3d0394820179 | 11 | |
ohlimi2 | 0:3d0394820179 | 12 | while(1) { |
ohlimi2 | 0:3d0394820179 | 13 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
ohlimi2 | 0:3d0394820179 | 14 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
ohlimi2 | 0:3d0394820179 | 15 | printf("measure = %.0f mV\n", meas); |
ohlimi2 | 0:3d0394820179 | 16 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
ohlimi2 | 0:3d0394820179 | 17 | led = 1; |
ohlimi2 | 0:3d0394820179 | 18 | } |
ohlimi2 | 0:3d0394820179 | 19 | else { |
ohlimi2 | 0:3d0394820179 | 20 | led = 0; |
ohlimi2 | 0:3d0394820179 | 21 | } |
ohlimi2 | 0:3d0394820179 | 22 | wait(0.2); // 200 ms |
ohlimi2 | 0:3d0394820179 | 23 | } |
ohlimi2 | 0:3d0394820179 | 24 | } |