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.
main.cpp@0:15495bc2362a, 2018-11-13 (annotated)
- Committer:
- lukofsky
- Date:
- Tue Nov 13 01:28:09 2018 +0000
- Revision:
- 0:15495bc2362a
- Child:
- 1:df1ae6d3fd03
j
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| lukofsky | 0:15495bc2362a | 1 | #include "mbed.h" |
| lukofsky | 0:15495bc2362a | 2 | |
| lukofsky | 0:15495bc2362a | 3 | AnalogIn analog_value(A0); |
| lukofsky | 0:15495bc2362a | 4 | |
| lukofsky | 0:15495bc2362a | 5 | DigitalOut led(LED1); |
| lukofsky | 0:15495bc2362a | 6 | |
| lukofsky | 0:15495bc2362a | 7 | int main() |
| lukofsky | 0:15495bc2362a | 8 | { |
| lukofsky | 0:15495bc2362a | 9 | float meas_r; |
| lukofsky | 0:15495bc2362a | 10 | float meas_v; |
| lukofsky | 0:15495bc2362a | 11 | |
| lukofsky | 0:15495bc2362a | 12 | printf("\nAnalogIn example\n"); |
| lukofsky | 0:15495bc2362a | 13 | |
| lukofsky | 0:15495bc2362a | 14 | while(1) { |
| lukofsky | 0:15495bc2362a | 15 | |
| lukofsky | 0:15495bc2362a | 16 | meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range) |
| lukofsky | 0:15495bc2362a | 17 | meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range |
| lukofsky | 0:15495bc2362a | 18 | |
| lukofsky | 0:15495bc2362a | 19 | // Display values |
| lukofsky | 0:15495bc2362a | 20 | printf("measure = %f = %.0f mV\n", meas_r, meas_v); |
| lukofsky | 0:15495bc2362a | 21 | |
| lukofsky | 0:15495bc2362a | 22 | // LED is ON is the value is below 1V |
| lukofsky | 0:15495bc2362a | 23 | if (meas_v < 1000) { |
| lukofsky | 0:15495bc2362a | 24 | led = 1; // LED ON |
| lukofsky | 0:15495bc2362a | 25 | } else { |
| lukofsky | 0:15495bc2362a | 26 | led = 0; // LED OFF |
| lukofsky | 0:15495bc2362a | 27 | } |
| lukofsky | 0:15495bc2362a | 28 | |
| lukofsky | 0:15495bc2362a | 29 | wait(1.0); // 1 second |
| lukofsky | 0:15495bc2362a | 30 | } |
| lukofsky | 0:15495bc2362a | 31 | } |