![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Read an analog value using ADC.
main.cpp@0:c2d1ad5059da, 2014-02-21 (annotated)
- Committer:
- bcostm
- Date:
- Fri Feb 21 10:22:49 2014 +0000
- Revision:
- 0:c2d1ad5059da
- Child:
- 1:0490a15c76e4
Initial version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:c2d1ad5059da | 1 | #include "mbed.h" |
bcostm | 0:c2d1ad5059da | 2 | |
bcostm | 0:c2d1ad5059da | 3 | AnalogIn analog_value(A0); |
bcostm | 0:c2d1ad5059da | 4 | |
bcostm | 0:c2d1ad5059da | 5 | DigitalOut myled(LED1); |
bcostm | 0:c2d1ad5059da | 6 | |
bcostm | 0:c2d1ad5059da | 7 | // Calculate the corresponding acquisition measure for a given value in mV |
bcostm | 0:c2d1ad5059da | 8 | #define MV(x) ((0xFFF*x)/3300) |
bcostm | 0:c2d1ad5059da | 9 | |
bcostm | 0:c2d1ad5059da | 10 | int main() { |
bcostm | 0:c2d1ad5059da | 11 | while(1) { |
bcostm | 0:c2d1ad5059da | 12 | uint16_t meas = analog_value.read_u16(); // Converts and read the analog input value |
bcostm | 0:c2d1ad5059da | 13 | if (meas > MV(1000)) { // If the value is greater than 1000 mV toggle the LED |
bcostm | 0:c2d1ad5059da | 14 | myled = !myled; |
bcostm | 0:c2d1ad5059da | 15 | } |
bcostm | 0:c2d1ad5059da | 16 | wait(0.2); // 200 ms |
bcostm | 0:c2d1ad5059da | 17 | } |
bcostm | 0:c2d1ad5059da | 18 | } |