Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@0:0dcfb07550ce, 2020-05-02 (annotated)
- Committer:
- corball
- Date:
- Sat May 02 11:51:01 2020 +0000
- Revision:
- 0:0dcfb07550ce
test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| corball | 0:0dcfb07550ce | 1 | #include "mbed.h" |
| corball | 0:0dcfb07550ce | 2 | |
| corball | 0:0dcfb07550ce | 3 | AnalogIn analog_value(A0); |
| corball | 0:0dcfb07550ce | 4 | |
| corball | 0:0dcfb07550ce | 5 | DigitalOut led(LED1); |
| corball | 0:0dcfb07550ce | 6 | |
| corball | 0:0dcfb07550ce | 7 | int main() |
| corball | 0:0dcfb07550ce | 8 | { |
| corball | 0:0dcfb07550ce | 9 | float meas_r; |
| corball | 0:0dcfb07550ce | 10 | float meas_v; |
| corball | 0:0dcfb07550ce | 11 | |
| corball | 0:0dcfb07550ce | 12 | printf("\nAnalogIn example\n"); |
| corball | 0:0dcfb07550ce | 13 | |
| corball | 0:0dcfb07550ce | 14 | while(1) { |
| corball | 0:0dcfb07550ce | 15 | |
| corball | 0:0dcfb07550ce | 16 | meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range) |
| corball | 0:0dcfb07550ce | 17 | meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range |
| corball | 0:0dcfb07550ce | 18 | |
| corball | 0:0dcfb07550ce | 19 | // Display values |
| corball | 0:0dcfb07550ce | 20 | printf("measure = %f = %.0f mV\n", meas_r, meas_v); |
| corball | 0:0dcfb07550ce | 21 | |
| corball | 0:0dcfb07550ce | 22 | // LED is ON is the value is below 1V |
| corball | 0:0dcfb07550ce | 23 | if (meas_v < 1000) { |
| corball | 0:0dcfb07550ce | 24 | led = 1; // LED ON |
| corball | 0:0dcfb07550ce | 25 | } else { |
| corball | 0:0dcfb07550ce | 26 | led = 0; // LED OFF |
| corball | 0:0dcfb07550ce | 27 | } |
| corball | 0:0dcfb07550ce | 28 | |
| corball | 0:0dcfb07550ce | 29 | wait(1.0); // 1 second |
| corball | 0:0dcfb07550ce | 30 | } |
| corball | 0:0dcfb07550ce | 31 | } |