Geert Huisman / IR_Distance
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IR_Dist.cpp Source File

IR_Dist.cpp

00001 #include "IR_Dist.h"
00002 #include "mbed.h"
00003 /*
00004 *IR_Dist.cpp
00005 */
00006 IR_Dist::IR_Dist(PinName a) : IRSens(a){}
00007 
00008  float IR_Dist::Equation() {   
00009     volts = IRSens.read_u16()* 0.02441406;                                      // 5v / 2048 = 0.02441406
00010      
00011     return 5034.2 * pow(volts,-0.959);                                          // x = 5034.2x-0.959
00012 }
00013  
00014 //return distance in cm 
00015 float IR_Dist::distance(){
00016     correction = 1;
00017     som = Equation();
00018     distance_cm = (som - correction);
00019     
00020     return distance_cm;
00021 
00022 }