zhaw_st16b_pes2_10 / Mbed 2 deprecated PES_Official-TestF

Dependencies:   Servo ServoArm mbed

Fork of PES_Official by zhaw_st16b_pes2_10

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Farbsensor.cpp Source File

Farbsensor.cpp

00001 #include "Robot.h"
00002 #include "Declarations.h"
00003 Serial pc1(USBTX, USBRX);
00004 
00005 Farbsensor::Farbsensor()
00006 {   
00007 }
00008 
00009 Farbsensor::Farbsensor(AnalogIn* FarbVoltage)
00010 {
00011     init(FarbVoltage);  
00012 }
00013 
00014 void Farbsensor::init(AnalogIn* FarbVoltage)
00015 {
00016     this->FarbVoltage= FarbVoltage;
00017 }
00018 
00019 int Farbsensor::read()
00020 {
00021     static int time=0;
00022     static float messungen=0.0f;
00023     if( time < 10 ){
00024         messungen += FarbVoltage->read();
00025         time++;
00026         return -1;
00027     }
00028     else{
00029         float Ufarbsensor = messungen/10.0;
00030         Ufarbsensor = Ufarbsensor*3300;//Set the Voltage between 0mV und 3300mV
00031         pc1.printf("measure = %.0f mV\n", Ufarbsensor); 
00032         
00033         messungen = 0.0f;
00034         time = 0;
00035         if ((Ufarbsensor > GREEN_DOWNLIMIT) && (Ufarbsensor < GREEN_UPLIMIT))
00036             {
00037              return GREEN;
00038             }
00039         else if(Ufarbsensor < RED_UPLIMIT)
00040             {
00041              return RED;
00042             }
00043         else 
00044             {
00045              return NOBLOCK;
00046             }
00047         }
00048 }
00049 
00050 Farbsensor::operator int()
00051 {
00052     return read();
00053 }