Read an analog value using ADC of the CORE-1000
Dependencies: mbed
main.cpp@3:5ad789860f24, 2017-02-03 (annotated)
- Committer:
- odb
- Date:
- Fri Feb 03 08:03:16 2017 +0000
- Revision:
- 3:5ad789860f24
- Parent:
- 1:0490a15c76e4
CORE-1000 First
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 | |
odb | 3:5ad789860f24 | 3 | // AnalogIn analog_value(PB_0); //psd sensor |
odb | 3:5ad789860f24 | 4 | AnalogIn analog_value(PC_1); |
bcostm | 0:c2d1ad5059da | 5 | |
bcostm | 1:0490a15c76e4 | 6 | DigitalOut led(LED1); |
bcostm | 1:0490a15c76e4 | 7 | |
bcostm | 0:c2d1ad5059da | 8 | int main() { |
bcostm | 1:0490a15c76e4 | 9 | float meas; |
bcostm | 1:0490a15c76e4 | 10 | |
odb | 3:5ad789860f24 | 11 | // printf("\nAnalogIn example\n"); |
odb | 3:5ad789860f24 | 12 | printf("\n Sensor Analog InPut example\n"); |
bcostm | 1:0490a15c76e4 | 13 | while(1) { |
bcostm | 1:0490a15c76e4 | 14 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
bcostm | 1:0490a15c76e4 | 15 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
odb | 3:5ad789860f24 | 16 | printf("measure = %.0f mV\n\r", meas); |
bcostm | 1:0490a15c76e4 | 17 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
bcostm | 1:0490a15c76e4 | 18 | led = 1; |
bcostm | 1:0490a15c76e4 | 19 | } |
bcostm | 1:0490a15c76e4 | 20 | else { |
bcostm | 1:0490a15c76e4 | 21 | led = 0; |
bcostm | 0:c2d1ad5059da | 22 | } |
bcostm | 0:c2d1ad5059da | 23 | wait(0.2); // 200 ms |
bcostm | 0:c2d1ad5059da | 24 | } |
bcostm | 0:c2d1ad5059da | 25 | } |