![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
für holdor
Fork of PES by
Roboter.cpp@0:306a2438de17, 2017-03-21 (annotated)
- Committer:
- itslinear
- Date:
- Tue Mar 21 12:42:01 2017 +0000
- Revision:
- 0:306a2438de17
- Child:
- 1:4e84271a70c6
hoiii
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
itslinear | 0:306a2438de17 | 1 | |
itslinear | 0:306a2438de17 | 2 | #include "Roboter.h" |
itslinear | 0:306a2438de17 | 3 | |
itslinear | 0:306a2438de17 | 4 | |
itslinear | 0:306a2438de17 | 5 | |
itslinear | 0:306a2438de17 | 6 | //timer object for ledshow and distance sensor |
itslinear | 0:306a2438de17 | 7 | Ticker t1; |
itslinear | 0:306a2438de17 | 8 | |
itslinear | 0:306a2438de17 | 9 | //lights up the led according to the sensor signal |
itslinear | 0:306a2438de17 | 10 | void ledDistance() |
itslinear | 0:306a2438de17 | 11 | { |
itslinear | 0:306a2438de17 | 12 | for( int ii = 0; ii<6; ++ii) |
itslinear | 0:306a2438de17 | 13 | sensors[ii]< 0.1f ? leds[ii] = 1 : leds[ii] = 0; |
itslinear | 0:306a2438de17 | 14 | } |
itslinear | 0:306a2438de17 | 15 | |
itslinear | 0:306a2438de17 | 16 | //blinks at startup and starts ledDistance task |
itslinear | 0:306a2438de17 | 17 | void ledShow() |
itslinear | 0:306a2438de17 | 18 | { |
itslinear | 0:306a2438de17 | 19 | static int timer = 0; |
itslinear | 0:306a2438de17 | 20 | for( int ii = 0; ii<6; ++ii) |
itslinear | 0:306a2438de17 | 21 | leds[ii] = !leds[ii]; |
itslinear | 0:306a2438de17 | 22 | |
itslinear | 0:306a2438de17 | 23 | //quit ticker and start led distance show |
itslinear | 0:306a2438de17 | 24 | if( ++timer > 10) { |
itslinear | 0:306a2438de17 | 25 | t1.detach(); |
itslinear | 0:306a2438de17 | 26 | t1.attach( &ledDistance, 0.01f ); |
itslinear | 0:306a2438de17 | 27 | } |
itslinear | 0:306a2438de17 | 28 | } |
itslinear | 0:306a2438de17 | 29 | |
itslinear | 0:306a2438de17 | 30 | int IRSensor() |
itslinear | 0:306a2438de17 | 31 | { |
itslinear | 0:306a2438de17 | 32 | pwmL.period(0.00005f); // Setzt die Periode auf 50 μs |
itslinear | 0:306a2438de17 | 33 | pwmR.period(0.00005f); |
itslinear | 0:306a2438de17 | 34 | |
itslinear | 0:306a2438de17 | 35 | pwmL = 0.5f; // Setzt die Duty-Cycle auf 50% |
itslinear | 0:306a2438de17 | 36 | pwmR = 0.5f; |
itslinear | 0:306a2438de17 | 37 | enableMotorDriver = 0; |
itslinear | 0:306a2438de17 | 38 | |
itslinear | 0:306a2438de17 | 39 | t1.attach( &ledShow, 0.05f ); |
itslinear | 0:306a2438de17 | 40 | |
itslinear | 0:306a2438de17 | 41 | //init distance sensors |
itslinear | 0:306a2438de17 | 42 | for( int ii = 0; ii<6; ++ii) |
itslinear | 0:306a2438de17 | 43 | sensors[ii].init(&distance, &bit0, &bit1, &bit2, ii); |
itslinear | 0:306a2438de17 | 44 | |
itslinear | 0:306a2438de17 | 45 | enable = 1; |
itslinear | 0:306a2438de17 | 46 | |
itslinear | 0:306a2438de17 | 47 | while(1) { |
itslinear | 0:306a2438de17 | 48 | wait( 0.2f ); |
itslinear | 0:306a2438de17 | 49 | } |
itslinear | 0:306a2438de17 | 50 | } |