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: mbed
IR_Sensor.cpp@0:b3438c44da56, 2018-04-27 (annotated)
- Committer:
- Alexander_Zuest
- Date:
- Fri Apr 27 12:07:56 2018 +0000
- Revision:
- 0:b3438c44da56
zug
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Alexander_Zuest | 0:b3438c44da56 | 1 | #include <cmath> |
| Alexander_Zuest | 0:b3438c44da56 | 2 | #include "IR_Sensor.h" |
| Alexander_Zuest | 0:b3438c44da56 | 3 | |
| Alexander_Zuest | 0:b3438c44da56 | 4 | using namespace std; |
| Alexander_Zuest | 0:b3438c44da56 | 5 | |
| Alexander_Zuest | 0:b3438c44da56 | 6 | IR_Sensor::IR_Sensor (AnalogIn& distance, DigitalOut& bit0,DigitalOut& bit1, DigitalOut& bit2, int number) : distance(distance), bit0(bit0), bit1(bit1), bit2(bit2) |
| Alexander_Zuest | 0:b3438c44da56 | 7 | { |
| Alexander_Zuest | 0:b3438c44da56 | 8 | this -> number = number; |
| Alexander_Zuest | 0:b3438c44da56 | 9 | } |
| Alexander_Zuest | 0:b3438c44da56 | 10 | IR_Sensor::~IR_Sensor() {} //Destruktor |
| Alexander_Zuest | 0:b3438c44da56 | 11 | |
| Alexander_Zuest | 0:b3438c44da56 | 12 | float IR_Sensor::read() { //Methode |
| Alexander_Zuest | 0:b3438c44da56 | 13 | { |
| Alexander_Zuest | 0:b3438c44da56 | 14 | |
| Alexander_Zuest | 0:b3438c44da56 | 15 | bit0 = (number >> 0) & 1; |
| Alexander_Zuest | 0:b3438c44da56 | 16 | bit1 = (number >> 1) & 3; |
| Alexander_Zuest | 0:b3438c44da56 | 17 | bit2 = (number >> 2) & 2; |
| Alexander_Zuest | 0:b3438c44da56 | 18 | |
| Alexander_Zuest | 0:b3438c44da56 | 19 | float d = -0.58f*squrt(distance)+0.58f; //Lesen der Distance |
| Alexander_Zuest | 0:b3438c44da56 | 20 | return d; |
| Alexander_Zuest | 0:b3438c44da56 | 21 | |
| Alexander_Zuest | 0:b3438c44da56 | 22 | } |