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:0367194b2909, 2019-03-05 (annotated)
- Committer:
- somlong
- Date:
- Tue Mar 05 06:55:03 2019 +0000
- Revision:
- 0:0367194b2909
1 test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| somlong | 0:0367194b2909 | 1 | #include "mbed.h" |
| somlong | 0:0367194b2909 | 2 | |
| somlong | 0:0367194b2909 | 3 | AnalogIn analog_value(A0); |
| somlong | 0:0367194b2909 | 4 | |
| somlong | 0:0367194b2909 | 5 | DigitalOut led(LED1); |
| somlong | 0:0367194b2909 | 6 | |
| somlong | 0:0367194b2909 | 7 | int main() { |
| somlong | 0:0367194b2909 | 8 | float meas; |
| somlong | 0:0367194b2909 | 9 | |
| somlong | 0:0367194b2909 | 10 | printf("\nAnalogIn example\n"); |
| somlong | 0:0367194b2909 | 11 | |
| somlong | 0:0367194b2909 | 12 | while(1) { |
| somlong | 0:0367194b2909 | 13 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
| somlong | 0:0367194b2909 | 14 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
| somlong | 0:0367194b2909 | 15 | printf("measure = %.0f mV\n", meas); |
| somlong | 0:0367194b2909 | 16 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
| somlong | 0:0367194b2909 | 17 | led = 1; |
| somlong | 0:0367194b2909 | 18 | } |
| somlong | 0:0367194b2909 | 19 | else { |
| somlong | 0:0367194b2909 | 20 | led = 1; |
| somlong | 0:0367194b2909 | 21 | } |
| somlong | 0:0367194b2909 | 22 | wait(0.2); // 200 ms |
| somlong | 0:0367194b2909 | 23 | } |
| somlong | 0:0367194b2909 | 24 | } |