![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Fertige Version mit geschwindigkeit 100
Dependencies: mbed
Fork of Micromouse_alpha_copy_copy by
IRSensor.cpp@0:a9fe4ef404bf, 2018-03-07 (annotated)
- Committer:
- ruesipat
- Date:
- Wed Mar 07 14:06:19 2018 +0000
- Revision:
- 0:a9fe4ef404bf
- Child:
- 1:d9e840c48b1e
hallo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ruesipat | 0:a9fe4ef404bf | 1 | #include <cmath> |
ruesipat | 0:a9fe4ef404bf | 2 | #include "IRSensor.h" |
ruesipat | 0:a9fe4ef404bf | 3 | |
ruesipat | 0:a9fe4ef404bf | 4 | using namespace std; |
ruesipat | 0:a9fe4ef404bf | 5 | |
ruesipat | 0:a9fe4ef404bf | 6 | IRSensor::IRSensor(AnalogIn& distance, DigitalOut& bit0, DigitalOut& bit1, DigitalOut& bit2, int number) : |
ruesipat | 0:a9fe4ef404bf | 7 | distance(distance), bit0(bit0), bit1(bit1), bit2(bit2) |
ruesipat | 0:a9fe4ef404bf | 8 | { |
ruesipat | 0:a9fe4ef404bf | 9 | this->number = number; |
ruesipat | 0:a9fe4ef404bf | 10 | } |
ruesipat | 0:a9fe4ef404bf | 11 | |
ruesipat | 0:a9fe4ef404bf | 12 | IRSensor::~IRSensor() {} |
ruesipat | 0:a9fe4ef404bf | 13 | |
ruesipat | 0:a9fe4ef404bf | 14 | float IRSensor::read() |
ruesipat | 0:a9fe4ef404bf | 15 | { |
ruesipat | 0:a9fe4ef404bf | 16 | |
ruesipat | 0:a9fe4ef404bf | 17 | bit0 = (number >> 0) & 1; |
ruesipat | 0:a9fe4ef404bf | 18 | bit1 = (number >> 1) & 1; |
ruesipat | 0:a9fe4ef404bf | 19 | bit2 = (number >> 2) & 1; |
ruesipat | 0:a9fe4ef404bf | 20 | |
ruesipat | 0:a9fe4ef404bf | 21 | float d = -0.58f*sqrt(distance)+0.58f; // Lesen der Distanz in [m] |
ruesipat | 0:a9fe4ef404bf | 22 | |
ruesipat | 0:a9fe4ef404bf | 23 | return d; |
ruesipat | 0:a9fe4ef404bf | 24 | |
ruesipat | 0:a9fe4ef404bf | 25 | } |