![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
vf
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
Diff: Sources/Farbsensor.cpp
- Revision:
- 12:c0bcb95885dd
- Parent:
- 10:f76476943a6c
- Child:
- 13:6c1f8e35b242
diff -r 292bdbd85a9c -r c0bcb95885dd Sources/Farbsensor.cpp --- a/Sources/Farbsensor.cpp Sat May 06 13:33:23 2017 +0000 +++ b/Sources/Farbsensor.cpp Wed May 10 13:30:13 2017 +0000 @@ -18,28 +18,31 @@ int Farbsensor::read() { - int farbe; - float Messungen=0.0; - for(int i=0;i<10;i++){ - Messungen+=FarbVoltage->read(); - wait(0.2); - } - float Ufarbsensor = Messungen/10.0; - Ufarbsensor = Ufarbsensor*3300; //Set the Voltage between 0mV und 3300mV - - if ((Ufarbsensor > GREEN_DOWNLIMIT) && (Ufarbsensor < GREEN_UPLIMIT)) - { - farbe=1; + 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; + } } - else if(Ufarbsensor < RED_UPLIMIT) - { - farbe=-1; - } - else - { - farbe=0; - } - return farbe; } Farbsensor::operator int()