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.
Fork of BinaryCount by
main.cpp@1:4647b43d61ef, 2017-03-27 (annotated)
- Committer:
- CSTritt
- Date:
- Mon Mar 27 14:29:20 2017 +0000
- Revision:
- 1:4647b43d61ef
- Parent:
- 0:8ed2f4a2a2fe
- Child:
- 2:5682a72277ed
- Child:
- 3:7448a1637704
Added reading and sending of digital state.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| CSTritt | 0:8ed2f4a2a2fe | 1 | /* |
| CSTritt | 0:8ed2f4a2a2fe | 2 | Project: analogRead_Overlaods |
| CSTritt | 0:8ed2f4a2a2fe | 3 | File: main.cpp |
| CSTritt | 0:8ed2f4a2a2fe | 4 | |
| CSTritt | 0:8ed2f4a2a2fe | 5 | Reads from analog input, streams ASCII text to std serial using printf, and |
| CSTritt | 0:8ed2f4a2a2fe | 6 | lights onboard LED. Also demonstrates use of floating point literal sufix to |
| CSTritt | 0:8ed2f4a2a2fe | 7 | eliminate warning and int constants for HIGH and LOW. This version uses |
| CSTritt | 1:4647b43d61ef | 8 | overloaded operators and sends LED state read from DigitalOut object. |
| CSTritt | 0:8ed2f4a2a2fe | 9 | |
| CSTritt | 0:8ed2f4a2a2fe | 10 | Written by: Dr. C. S. Tritt |
| CSTritt | 0:8ed2f4a2a2fe | 11 | Created: 3/26/17 (v. 1.0) |
| CSTritt | 0:8ed2f4a2a2fe | 12 | |
| CSTritt | 0:8ed2f4a2a2fe | 13 | */ |
| CSTritt | 0:8ed2f4a2a2fe | 14 | #include "mbed.h" |
| CSTritt | 0:8ed2f4a2a2fe | 15 | |
| CSTritt | 0:8ed2f4a2a2fe | 16 | const int HIGH = 1; // Optional, but makes code more readable. |
| CSTritt | 0:8ed2f4a2a2fe | 17 | const int LOW = 0; // Optional, but makes code more readable. |
| CSTritt | 0:8ed2f4a2a2fe | 18 | |
| CSTritt | 0:8ed2f4a2a2fe | 19 | AnalogIn analog_value(A0); |
| CSTritt | 0:8ed2f4a2a2fe | 20 | |
| CSTritt | 0:8ed2f4a2a2fe | 21 | DigitalOut led(LED1); |
| CSTritt | 0:8ed2f4a2a2fe | 22 | |
| CSTritt | 0:8ed2f4a2a2fe | 23 | int main() { |
| CSTritt | 0:8ed2f4a2a2fe | 24 | float value; // Value to be read and sent to serial port. |
| CSTritt | 0:8ed2f4a2a2fe | 25 | |
| CSTritt | 0:8ed2f4a2a2fe | 26 | printf("\nAnalogIn example\n"); |
| CSTritt | 0:8ed2f4a2a2fe | 27 | |
| CSTritt | 0:8ed2f4a2a2fe | 28 | while(true) { |
| CSTritt | 0:8ed2f4a2a2fe | 29 | value = analog_value; // Read the analog input value (0 to 1) |
| CSTritt | 0:8ed2f4a2a2fe | 30 | printf("Value = %f\n", value); // Send value as text via serial port. |
| CSTritt | 0:8ed2f4a2a2fe | 31 | if (value > 0.5f) { // Activate built-in LED. The f is optional. |
| CSTritt | 0:8ed2f4a2a2fe | 32 | led = HIGH; |
| CSTritt | 0:8ed2f4a2a2fe | 33 | } |
| CSTritt | 0:8ed2f4a2a2fe | 34 | else { |
| CSTritt | 0:8ed2f4a2a2fe | 35 | led = LOW; |
| CSTritt | 0:8ed2f4a2a2fe | 36 | } |
| CSTritt | 1:4647b43d61ef | 37 | printf("LED = %d\n", (int) led); // Send LED state as serial text. |
| CSTritt | 0:8ed2f4a2a2fe | 38 | wait(0.25); // 250 ms |
| CSTritt | 0:8ed2f4a2a2fe | 39 | } |
| CSTritt | 0:8ed2f4a2a2fe | 40 | } |
