Test capteur distant IR

Dependencies:   mbed

Fork of GP2Y0A710K0F_HelloWold by Christian Dupaty

main.cpp

Committer:
cdupaty
Date:
2016-04-30
Revision:
3:70d33938ad46
Parent:
1:0490a15c76e4

File content as of revision 3:70d33938ad46:

#include "mbed.h"
 
AnalogIn GP2Y0A710K0F(A0);
 
DigitalOut led(LED1);

int main() {
    float mes;
    
    printf("\nAnalogIn example\n");
    
    while(1) {
        mes = GP2Y0A710K0F.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
        mes = mes * 3300; // Change the value to be in the 0 to 3300 range
        printf("mesure = %.0f mV\n\r", mes);
        if (mes > 2000) { // If the value is greater than 2V then switch the LED on
          led = 1;
        }
        else {
          led = 0;
        }
        wait(0.2); // 200 ms
    }
}