In a programming language of your choice, implement the top level of the robot controller hierarchy.

Here is one possible solution:

input variables: sensor, last_goal
output variables: last_goal, goal
constants: light_threshold, dark_threshold

robot

Code:
if (last_goal == true && sensor > light_threshold) {
	goal = false;
} else if (last_goal == false && sensor < dark_threshold) {
	goal = true;
}
last_goal = goal;

Valid HTML 4.0 Transitional