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 AnalogIn_HelloWorld_WIZwiki-W7500 by
main.cpp@3:abab0082e271, 2015-07-02 (annotated)
- Committer:
- joon874
- Date:
- Thu Jul 02 07:34:56 2015 +0000
- Revision:
- 3:abab0082e271
- Parent:
- 2:5f564266c94f
- Child:
- 5:97fa889845b0
Analog Input example for WIZwiki-W7500 Academy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joon874 | 3:abab0082e271 | 1 | /* Analog Input Example Program */ |
sam_grove | 0:101a12a915c6 | 2 | |
sam_grove | 0:101a12a915c6 | 3 | #include "mbed.h" |
sam_grove | 0:101a12a915c6 | 4 | |
sam_grove | 0:101a12a915c6 | 5 | // Initialize a pins to perform analog input and digital output fucntions |
joon874 | 3:abab0082e271 | 6 | AnalogIn ain(A0); |
joon874 | 3:abab0082e271 | 7 | DigitalOut myled(LED1); // on-board LED_RED |
sam_grove | 0:101a12a915c6 | 8 | |
sam_grove | 0:101a12a915c6 | 9 | int main(void) |
sam_grove | 0:101a12a915c6 | 10 | { |
sam_grove | 0:101a12a915c6 | 11 | while (1) { |
sam_grove | 0:101a12a915c6 | 12 | // test the voltage on the initialized analog pin |
joon874 | 3:abab0082e271 | 13 | // and if greater than 0.4 * VCC set the digital pin |
sam_grove | 0:101a12a915c6 | 14 | // to a logic 1 otherwise a logic 0 |
joon874 | 3:abab0082e271 | 15 | if(ain > 0.4f) { |
joon874 | 3:abab0082e271 | 16 | myled = 1; // Red LED Off |
sam_grove | 0:101a12a915c6 | 17 | } else { |
joon874 | 3:abab0082e271 | 18 | myled = 0; // Red LED On |
sam_grove | 0:101a12a915c6 | 19 | } |
sam_grove | 0:101a12a915c6 | 20 | |
joon874 | 3:abab0082e271 | 21 | // print the percentage and normalized values |
joon874 | 2:5f564266c94f | 22 | printf("percentage: %3.3f%%\r\n", ain.read()*100.0f); |
joon874 | 2:5f564266c94f | 23 | printf("analog value : %3.3f\r\n", ain.read()); |
joon874 | 2:5f564266c94f | 24 | wait(1.0); |
sam_grove | 0:101a12a915c6 | 25 | } |
sam_grove | 0:101a12a915c6 | 26 | } |
joon874 | 3:abab0082e271 | 27 | |
joon874 | 3:abab0082e271 | 28 | |
joon874 | 3:abab0082e271 | 29 | |
joon874 | 3:abab0082e271 | 30 | |
joon874 | 3:abab0082e271 | 31 | |
joon874 | 3:abab0082e271 | 32 | |
joon874 | 3:abab0082e271 | 33 | |
joon874 | 3:abab0082e271 | 34 | |
joon874 | 3:abab0082e271 | 35 |