Test capteur distant IR
Dependencies: mbed
Fork of GP2Y0A710K0F_HelloWold by
main.cpp@3:70d33938ad46, 2016-04-30 (annotated)
- Committer:
- cdupaty
- Date:
- Sat Apr 30 17:04:19 2016 +0000
- Revision:
- 3:70d33938ad46
- Parent:
- 1:0490a15c76e4
test? et mis ? jour pour BTSSN
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 | |
cdupaty | 3:70d33938ad46 | 3 | AnalogIn GP2Y0A710K0F(A0); |
bcostm | 0:c2d1ad5059da | 4 | |
bcostm | 1:0490a15c76e4 | 5 | DigitalOut led(LED1); |
bcostm | 1:0490a15c76e4 | 6 | |
bcostm | 0:c2d1ad5059da | 7 | int main() { |
cdupaty | 3:70d33938ad46 | 8 | float mes; |
bcostm | 1:0490a15c76e4 | 9 | |
bcostm | 1:0490a15c76e4 | 10 | printf("\nAnalogIn example\n"); |
bcostm | 1:0490a15c76e4 | 11 | |
bcostm | 1:0490a15c76e4 | 12 | while(1) { |
cdupaty | 3:70d33938ad46 | 13 | mes = GP2Y0A710K0F.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
cdupaty | 3:70d33938ad46 | 14 | mes = mes * 3300; // Change the value to be in the 0 to 3300 range |
cdupaty | 3:70d33938ad46 | 15 | printf("mesure = %.0f mV\n\r", mes); |
cdupaty | 3:70d33938ad46 | 16 | if (mes > 2000) { // If the value is greater than 2V then switch the LED on |
bcostm | 1:0490a15c76e4 | 17 | led = 1; |
bcostm | 1:0490a15c76e4 | 18 | } |
bcostm | 1:0490a15c76e4 | 19 | else { |
bcostm | 1:0490a15c76e4 | 20 | led = 0; |
bcostm | 0:c2d1ad5059da | 21 | } |
bcostm | 0:c2d1ad5059da | 22 | wait(0.2); // 200 ms |
bcostm | 0:c2d1ad5059da | 23 | } |
bcostm | 0:c2d1ad5059da | 24 | } |