Analog Input example for WIZWiki-W7500 Academy
Dependencies: mbed
Fork of AnalogIn_HelloWorld_WIZwiki-W7500 by
main.cpp@8:bc6291805741, 2016-02-03 (annotated)
- Committer:
- IOP
- Date:
- Wed Feb 03 07:27:16 2016 +0000
- Revision:
- 8:bc6291805741
- Parent:
- 7:6b50af097b44
put some comments
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 | |
IOP | 8:bc6291805741 | 5 | DigitalOut myled_R(LED_RED); |
IOP | 8:bc6291805741 | 6 | |
IOP | 8:bc6291805741 | 7 | AnalogIn ain(A0); |
IOP | 8:bc6291805741 | 8 | |
sam_grove | 0:101a12a915c6 | 9 | |
sam_grove | 0:101a12a915c6 | 10 | int main(void) |
IOP | 6:885e2cb16d7d | 11 | { |
IOP | 7:6b50af097b44 | 12 | int ain_val = 0; |
IOP | 5:97fa889845b0 | 13 | |
IOP | 7:6b50af097b44 | 14 | while (1) { |
IOP | 7:6b50af097b44 | 15 | |
IOP | 7:6b50af097b44 | 16 | ain_val = ain.read()*1000; |
IOP | 7:6b50af097b44 | 17 | |
IOP | 8:bc6291805741 | 18 | // Compare between 'Specific value' and 'Analog Input value' |
IOP | 8:bc6291805741 | 19 | if(ain_val > 500) |
IOP | 8:bc6291805741 | 20 | { |
IOP | 8:bc6291805741 | 21 | myled_R = 1; // Red LED OFF |
IOP | 8:bc6291805741 | 22 | } |
IOP | 8:bc6291805741 | 23 | else |
IOP | 8:bc6291805741 | 24 | { |
IOP | 8:bc6291805741 | 25 | myled_R = 0; // Red LED ON |
IOP | 8:bc6291805741 | 26 | } |
sam_grove | 0:101a12a915c6 | 27 | |
IOP | 5:97fa889845b0 | 28 | // output the voltage and analog values |
IOP | 6:885e2cb16d7d | 29 | printf("======================\r\n"); |
IOP | 8:bc6291805741 | 30 | printf("voltage value : %3.3f\r\n", ain.read()*3.3f); // voltage 0.0V ~ 3.3V |
IOP | 8:bc6291805741 | 31 | printf("analog value : %3.3f\r\n", ain.read()); // analog value 0.0 ~ 1.0 |
IOP | 8:bc6291805741 | 32 | printf("analog value x1000 : %d\r\n",ain_val); // analog value 0 ~ 1000 |
joon874 | 2:5f564266c94f | 33 | wait(1.0); |
sam_grove | 0:101a12a915c6 | 34 | } |
sam_grove | 0:101a12a915c6 | 35 | } |
joon874 | 3:abab0082e271 | 36 | |
joon874 | 3:abab0082e271 | 37 | |
joon874 | 3:abab0082e271 | 38 | |
joon874 | 3:abab0082e271 | 39 | |
joon874 | 3:abab0082e271 | 40 | |
joon874 | 3:abab0082e271 | 41 | |
joon874 | 3:abab0082e271 | 42 | |
joon874 | 3:abab0082e271 | 43 | |
joon874 | 3:abab0082e271 | 44 |