Do NOT modify!

Dependencies:   mbed Servo ServoArm

Fork of PES_Yanick by zhaw_st16b_pes2_10

Sources/Farbsensor.cpp

Committer:
beacon
Date:
2017-05-10
Revision:
12:c0bcb95885dd
Parent:
10:f76476943a6c

File content as of revision 12:c0bcb95885dd:

#include "Robot.h"
#include "Declarations.h"


Farbsensor::Farbsensor()
{   
}

Farbsensor::Farbsensor(AnalogIn* FarbVoltage)
{
    init(FarbVoltage);  
}

void Farbsensor::init(AnalogIn* FarbVoltage)
{
    this->FarbVoltage= FarbVoltage;
}

int Farbsensor::read()
{
    static int time=0;
    static float Messungen=0.0f;
    if( time < 10 ){
        Messungen += FarbVoltage->read();
        time++;
        return -1;
    }
    else{
        time = 0;
        float Ufarbsensor = Messungen/10.0;
        Ufarbsensor = Ufarbsensor*3300; //Set the Voltage between 0mV und 3300mV
    
        if ((Ufarbsensor > GREEN_DOWNLIMIT) && (Ufarbsensor < GREEN_UPLIMIT))
            {
             return GREEN;
            }
        else if(Ufarbsensor < RED_UPLIMIT)
            {
             return RED;
            }
        else 
            {
             return NOBLOCK;
            }
        }
}

Farbsensor::operator int()
{
    return read();
}