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