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