![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Roboter
Diff: Roboter.cpp
- Revision:
- 0:306a2438de17
- Child:
- 1:4e84271a70c6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Roboter.cpp Tue Mar 21 12:42:01 2017 +0000 @@ -0,0 +1,50 @@ + +#include "Roboter.h" + + + +//timer object for ledshow and distance sensor +Ticker t1; + +//lights up the led according to the sensor signal +void ledDistance() +{ + for( int ii = 0; ii<6; ++ii) + sensors[ii]< 0.1f ? leds[ii] = 1 : leds[ii] = 0; +} + +//blinks at startup and starts ledDistance task +void ledShow() +{ + static int timer = 0; + for( int ii = 0; ii<6; ++ii) + leds[ii] = !leds[ii]; + + //quit ticker and start led distance show + if( ++timer > 10) { + t1.detach(); + t1.attach( &ledDistance, 0.01f ); + } +} + +int IRSensor() +{ + pwmL.period(0.00005f); // Setzt die Periode auf 50 μs + pwmR.period(0.00005f); + + pwmL = 0.5f; // Setzt die Duty-Cycle auf 50% + pwmR = 0.5f; + enableMotorDriver = 0; + + t1.attach( &ledShow, 0.05f ); + + //init distance sensors + for( int ii = 0; ii<6; ++ii) + sensors[ii].init(&distance, &bit0, &bit1, &bit2, ii); + + enable = 1; + + while(1) { + wait( 0.2f ); + } +}