79
Using Interrupts (advanced programming)
It is important that the program does not spend all of its time polling the sensor to determine the
distance to an object. To allow the STEM Board processor to perform more than one task such as
sensing the distance using the ultrasonic and controlling the motors for line following, interrupts will be
used. Interrupt control is a technique which allows the STEM Board to temporarily suspends what is
doing (such are controlling the motors) to service a change on an input pin (such as a timed ultrasonic
echo response). This effectively allows the STEM Board to perform two tasks at the same time.
A program demonstrating the use of interrupt control for the ultrasonic sensor will be available soon.
Obstacle Avoidance Using the Ultrasonic Sensor
In this lesson, you will program your Pi-Bot to prevent accidents. Combining with what we have learned
about the ultrasonic sensor and motion control, we shall now investigate obstacle avoidance. Using the
program shown below, your Pi-Bot will continue forward at a medium speed until an obstacle is
detected within 10cm of the sensor. Upon detecting the object in front of the sensor, your Pi-Bot will
reverse and make a left turn, and then will proceed go forward.
The program has numerous print statements. Open the serial monitor window to see what is going on.
Once you understand, you can turn off all the print statements and serial monitor.
Summary of Contents for Pi-Bot v2.00
Page 67: ...67 Figure 6 15 ...
Page 78: ...78 UltraSonicSensorTestwithLED Program ...
Page 80: ...80 ObstacleAvoidance Program ...
Page 82: ...82 ObstacleAvoidancewithLED Program ...
Page 83: ...83 ObstacleAvoidancewithLED Program CONTINUED ...
Page 90: ...90 Download and run the following program LineFollowing Program ...
Page 91: ...91 LineFollowing Program CONTINUED ...
Page 94: ...94 AdvancedLineFollowing Program CONTINUED ...
Page 95: ...95 AdvancedLineFollowing Program CONTINUED ...
Page 96: ...96 AdvancedLineFollowing Program CONTINUED ...
Page 110: ...Appendix B Complete Pi Bot Wiring Schematic ...