Objective
To build and program a robot to move towards light and stop when touched.
Final Program
Flowchart
Look up Chapter 3 from the book to create the Come-To-Light Program.
Alternate Program for the "Insect" using a State Machine
The final program for the state machine for the above flowchart is given below. Note that there are four images, which are each cases of one program.
Figure : Case "Look for light" where the robot is to search for light above a particular threshold.
Figure : Case "Move Toward Light", where the robot moves (while checking for conditions in other cases)
Figure : Case "Wait for touch", where the robot, while searching for light and moving towards a light, when it finds it, it will also keep checking if the touch sensor is depressed.
Figure : Case "Stop" where the program is stopped, when this case is active, which you can see (from the "Wait for Touch") is decided based on whether the touch sensor is pressed or not