# a simple function that flashes the robot's back light a specified number of times # Notice the use of wait to create a pause def flashLight(times): for i in range(times): setLED("back",1) wait(0.55) setLED("back",0) wait(0.25) def senseLoop(): # getLight() is a function that gives back three values # Here we save them in three variables. # This is a really unusual line of code, so don't worry if it doesn't make much sense. # Remember variables from Scratch, though? They store data. rightSensor, centerSensor, leftSensor = getLight() # Print out all three sensor values print "Light Sensor Values:", rightSensor, centerSensor, leftSensor; # If the right sensor is covered if rightSensor > 2000: # You can write a song using note names and beat lengths playSong(makeSong("c 1; g 1/4; a 1/2; e 3/4;") ) # Make the back LED flash flashLight(5) # If the center sensor is covered if centerSensor > 5000: print "BAGELS BAGELS GGRRAA" # don't ask; it's late wait(0.25) beep(0.25,440,880) # If the left sensor is covered if leftSensor > 2000: turnLeft(1,0.5) # Continue sensing for 20 seconds while(timeRemaining(20)): senseLoop()