Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Servo ServoArm mbed
Fork of PES_Official-TestF by
Sources/Farbsensor.cpp
- Committer:
- EpicG10
- Date:
- 2017-05-19
- Revision:
- 18:a158713a0049
- Parent:
- 13:6c1f8e35b242
File content as of revision 18:a158713a0049:
#include "Robot.h"
#include "Declarations.h"
Serial pc1(USBTX, USBRX);
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{
float Ufarbsensor = messungen/10.0;
Ufarbsensor = Ufarbsensor*3300;//Set the Voltage between 0mV und 3300mV
pc1.printf("measure = %.0f mV\n", Ufarbsensor);
messungen = 0.0f;
time = 0;
if ((Ufarbsensor > GREEN_DOWNLIMIT) && (Ufarbsensor < GREEN_UPLIMIT))
{
return GREEN;
}
else if(Ufarbsensor < RED_UPLIMIT)
{
return RED;
}
else
{
return NOBLOCK;
}
}
}
Farbsensor::operator int()
{
return read();
}
