![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
vf
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
Sources/Farbsensor.cpp@17:4e1be70bdedb, 2017-05-18 (annotated)
- Committer:
- beacon
- Date:
- Thu May 18 14:27:09 2017 +0000
- Revision:
- 17:4e1be70bdedb
- Parent:
- 13:6c1f8e35b242
Si compila.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beacon | 1:388c915756f5 | 1 | #include "Robot.h" |
beacon | 4:67d7177c213f | 2 | #include "Declarations.h" |
EpicG10 | 13:6c1f8e35b242 | 3 | Serial pc1(USBTX, USBRX); |
beacon | 1:388c915756f5 | 4 | |
beacon | 1:388c915756f5 | 5 | Farbsensor::Farbsensor() |
beacon | 1:388c915756f5 | 6 | { |
beacon | 1:388c915756f5 | 7 | } |
beacon | 1:388c915756f5 | 8 | |
beacon | 1:388c915756f5 | 9 | Farbsensor::Farbsensor(AnalogIn* FarbVoltage) |
beacon | 1:388c915756f5 | 10 | { |
beacon | 1:388c915756f5 | 11 | init(FarbVoltage); |
beacon | 1:388c915756f5 | 12 | } |
beacon | 1:388c915756f5 | 13 | |
beacon | 1:388c915756f5 | 14 | void Farbsensor::init(AnalogIn* FarbVoltage) |
beacon | 1:388c915756f5 | 15 | { |
beacon | 1:388c915756f5 | 16 | this->FarbVoltage= FarbVoltage; |
beacon | 1:388c915756f5 | 17 | } |
beacon | 1:388c915756f5 | 18 | |
beacon | 1:388c915756f5 | 19 | int Farbsensor::read() |
beacon | 1:388c915756f5 | 20 | { |
beacon | 12:c0bcb95885dd | 21 | static int time=0; |
EpicG10 | 13:6c1f8e35b242 | 22 | static float messungen=0.0f; |
beacon | 12:c0bcb95885dd | 23 | if( time < 10 ){ |
EpicG10 | 13:6c1f8e35b242 | 24 | messungen += FarbVoltage->read(); |
beacon | 12:c0bcb95885dd | 25 | time++; |
beacon | 12:c0bcb95885dd | 26 | return -1; |
beacon | 12:c0bcb95885dd | 27 | } |
beacon | 12:c0bcb95885dd | 28 | else{ |
EpicG10 | 13:6c1f8e35b242 | 29 | float Ufarbsensor = messungen/10.0; |
EpicG10 | 13:6c1f8e35b242 | 30 | Ufarbsensor = Ufarbsensor*3300;//Set the Voltage between 0mV und 3300mV |
EpicG10 | 13:6c1f8e35b242 | 31 | pc1.printf("measure = %.0f mV\n", Ufarbsensor); |
EpicG10 | 13:6c1f8e35b242 | 32 | |
EpicG10 | 13:6c1f8e35b242 | 33 | messungen = 0.0f; |
beacon | 12:c0bcb95885dd | 34 | time = 0; |
beacon | 12:c0bcb95885dd | 35 | if ((Ufarbsensor > GREEN_DOWNLIMIT) && (Ufarbsensor < GREEN_UPLIMIT)) |
beacon | 12:c0bcb95885dd | 36 | { |
beacon | 12:c0bcb95885dd | 37 | return GREEN; |
beacon | 12:c0bcb95885dd | 38 | } |
beacon | 12:c0bcb95885dd | 39 | else if(Ufarbsensor < RED_UPLIMIT) |
beacon | 12:c0bcb95885dd | 40 | { |
beacon | 12:c0bcb95885dd | 41 | return RED; |
beacon | 12:c0bcb95885dd | 42 | } |
beacon | 12:c0bcb95885dd | 43 | else |
beacon | 12:c0bcb95885dd | 44 | { |
beacon | 12:c0bcb95885dd | 45 | return NOBLOCK; |
beacon | 12:c0bcb95885dd | 46 | } |
beacon | 1:388c915756f5 | 47 | } |
beacon | 1:388c915756f5 | 48 | } |
beacon | 1:388c915756f5 | 49 | |
beacon | 1:388c915756f5 | 50 | Farbsensor::operator int() |
beacon | 1:388c915756f5 | 51 | { |
beacon | 1:388c915756f5 | 52 | return read(); |
beacon | 1:388c915756f5 | 53 | } |