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.
Revision 3:f879eeeb5e8d, committed 2020-02-08
- Comitter:
- CSTritt
- Date:
- Sat Feb 08 18:39:55 2020 +0000
- Parent:
- 2:e0faf9e57796
- Commit message:
- Initial version of potentiometer (analog) to serial program.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r e0faf9e57796 -r f879eeeb5e8d main.cpp --- a/main.cpp Mon Mar 27 14:20:32 2017 +0000 +++ b/main.cpp Sat Feb 08 18:39:55 2020 +0000 @@ -1,19 +1,21 @@ /* - Project: analogRead + Project: potSerial File: main.cpp Reads from analog input, streams ASCII text to std serial using printf and lights onboard LED. Also demonstrates use of floating point literal suffix - toeliminate warning and int constants for HIGH and LOW. + to eliminate warning and int constants for HIGH and LOW. Written by: Dr. C. S. Tritt - Created: 3/27/17 (v. 1.1) + Created: 2/8/20 (v. 1.0) */ #include "mbed.h" const int HIGH = 1; // Optional, but makes code more readable. const int LOW = 0; // Optional, but makes code more readable. +const float WAIT = 0.25f; // Wait time between samples (s). +const float LIGHT = 0.5f; // Analog value (0 to 1 scale) to light LED. AnalogIn analog_value(A0); @@ -22,18 +24,17 @@ int main() { float value; // Value to be read and sent to serial port. - printf("\nAnalogIn example\n"); + printf("\nAnalog to serial example.\n"); while(true) { value = analog_value.read(); // Read the analog input value (0 to 1) - printf("Value = %f\n", value); // Send value as text via serial port. - if (value > 0.5f) { // Activate built-in LED. The f is optional. + printf("%f\n", value); // Send value as text via serial port. + if (value > LIGHT) { // Activate built-in LED based on LIGHT value. led.write(HIGH); } else { led.write(LOW); } - printf("LED = %d\n", (int) led.read()); // Send LED state via serial. - wait(0.25); // 250 ms + wait(WAIT); // Wait WAIT seconds. } -} +} \ No newline at end of file
diff -r e0faf9e57796 -r f879eeeb5e8d mbed.bld --- a/mbed.bld Mon Mar 27 14:20:32 2017 +0000 +++ b/mbed.bld Sat Feb 08 18:39:55 2020 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file