# Jay Summet # Released to the Public Domain: October 2007 #Example showing a Finite State Machine and #demonstrating the use of a variable to point to a function. from myro import * initialize() behavior = None def run(): global behavior forward(1,2) def flee(): global behavior backward(1,1) turnLeft(1,0.5) backward(1,1) behavior = takeReading def takeReading(): global behavior reading = getLight("center") print "Reading is: ", reading if (reading > 250): beep(1,800) behavior = run else: speak("It's Bright!") behavior = flee def brain(): global behavior behavior = flee for i in range(5): behavior() brain()