![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
sef
Dependencies: mbed
Fork of Bewegungen_mit_Sensor by
Diff: IRSensor.cpp
- Revision:
- 2:365bf16abbf6
- Parent:
- 1:d40ff07e2fe0
diff -r d40ff07e2fe0 -r 365bf16abbf6 IRSensor.cpp --- a/IRSensor.cpp Wed May 10 09:14:12 2017 +0000 +++ b/IRSensor.cpp Tue May 16 14:14:08 2017 +0000 @@ -11,24 +11,28 @@ IRSensor::IRSensor() {} -IRSensor::IRSensor(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number) { +IRSensor::IRSensor(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number) +{ this->distance = distance; //Weist den Objektvariablen, die eingegebenen Werte zu this->bit0 = bit0; this->bit1 = bit1; this->bit2 = bit2; this->number = number; + this->filteredValue = 0.0f; } //Destruktor -> Löscht das IRSensor-Objekt IRSensor::~IRSensor() {} //Initialisiert nachträglich -void IRSensor::init(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number) { +void IRSensor::init(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number) +{ this->distance = distance; //Weist den Objektvariablen, die eingegebenen Werte zu this->bit0 = bit0; this->bit1 = bit1; this->bit2 = bit2; this->number = number; + this->filteredValue = 0.0f; } //Distanzrechner @@ -39,5 +43,13 @@ *bit2 = (number >> 2) & 1; //Vergleicht das dritte Bit von rechts float d = distance->read(); + + this->filteredValue = 0.99f* this->filteredValue + 0.01f * d; return d; -} \ No newline at end of file +} + +float IRSensor::readFitered() +{ + return this->filteredValue; +} +