Gabriel Jaffres
/
accordeur
y
main.cpp@1:924f6cf87f06, 2019-06-03 (annotated)
- Committer:
- jahfresh
- Date:
- Mon Jun 03 11:58:38 2019 +0000
- Revision:
- 1:924f6cf87f06
- Parent:
- 0:f23ecbd3f3b5
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jahfresh | 0:f23ecbd3f3b5 | 1 | #include "mbed.h" |
jahfresh | 0:f23ecbd3f3b5 | 2 | |
jahfresh | 0:f23ecbd3f3b5 | 3 | AnalogIn analog_value(A0); |
jahfresh | 0:f23ecbd3f3b5 | 4 | |
jahfresh | 0:f23ecbd3f3b5 | 5 | DigitalOut led(LED1); |
jahfresh | 0:f23ecbd3f3b5 | 6 | |
jahfresh | 0:f23ecbd3f3b5 | 7 | int main() { |
jahfresh | 0:f23ecbd3f3b5 | 8 | float meas; |
jahfresh | 0:f23ecbd3f3b5 | 9 | |
jahfresh | 0:f23ecbd3f3b5 | 10 | printf("\nAnalogIn example\n"); |
jahfresh | 0:f23ecbd3f3b5 | 11 | |
jahfresh | 0:f23ecbd3f3b5 | 12 | while(1) { |
jahfresh | 0:f23ecbd3f3b5 | 13 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
jahfresh | 0:f23ecbd3f3b5 | 14 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
jahfresh | 0:f23ecbd3f3b5 | 15 | printf("measure = %.0f mV\n", meas); |
jahfresh | 0:f23ecbd3f3b5 | 16 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
jahfresh | 0:f23ecbd3f3b5 | 17 | led = 1; |
jahfresh | 0:f23ecbd3f3b5 | 18 | } |
jahfresh | 0:f23ecbd3f3b5 | 19 | else { |
jahfresh | 0:f23ecbd3f3b5 | 20 | led = 0; |
jahfresh | 0:f23ecbd3f3b5 | 21 | } |
jahfresh | 1:924f6cf87f06 | 22 | wait(0.2); // 200 ms test |
jahfresh | 0:f23ecbd3f3b5 | 23 | } |
jahfresh | 0:f23ecbd3f3b5 | 24 | } |