Antonia Baumgartner / Mbed 2 deprecated Versuch21

Dependencies:   mbed

Fork of Versuch20 by Alexander Wyss

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IRSensorGF.cpp Source File

IRSensorGF.cpp

00001 #include <cmath>
00002 #include "IRSensorGF.h"
00003 
00004 //------------------------------------------------------------------------------
00005 
00006 using namespace std;
00007 
00008 IRSensorGF::IRSensorGF(AnalogIn& distance):
00009 
00010     distance(distance)
00011 {
00012 
00013 
00014 }
00015 
00016 IRSensorGF::~IRSensorGF() {}
00017 
00018 //------------------------------------------------------------------------------
00019 
00020 int IRSensorGF::read()
00021 {
00022     int d;
00023 
00024     /*if (3300*(distance)>2900){     //5-6cm
00025        d=1;
00026        }
00027     else{
00028        d=0;
00029        }*/
00030 
00031     int w = 10/(distance)*exp(1.4481);
00032 
00033     if (w < 150) {
00034         d=1;
00035     } else {
00036         d=0;
00037     }
00038 
00039     return w;
00040 
00041 }