MEM / Mbed 2 deprecated ES_2_P5

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #define soglia 1000
00003 Serial pc(USBTX,USBRX);
00004 unsigned int RCtime();
00005 unsigned int photoR;
00006 DigitalOut out(D6);
00007 DigitalInOut sens(D4);
00008 
00009 int main()
00010 {
00011     pc.printf("ADC data values...\n\r");
00012     while (1) {
00013         photoR = RCtime();
00014         
00015         if(photoR == 30000){
00016             pc.printf("Nothing connected...\n\r");
00017             }
00018         else {
00019             pc.printf("RC time reading = ");
00020             pc.printf("%u\n\r",photoR);
00021             
00022             if(photoR>soglia){
00023                 out=1;
00024                 }
00025             else{
00026                 out=0;
00027                  }
00028               }
00029     wait(0.1);
00030                 }
00031     }
00032 
00033 unsigned int RCtime()
00034 {
00035     int reading = 0;
00036     sens.output();
00037     sens=0;
00038     wait_ms(10);
00039     sens.input();
00040     while(sens == 0){
00041         reading++;
00042         if(reading == 30000){
00043             break;
00044             }
00045         }
00046     return reading;
00047     }