PYTHON   45
LightCycle
Guest on 1st February 2023 01:34:00 AM


  1. from cozmo_fsm import *
  2. from cozmo.lights import *
  3.  
  4. #Runs the light cycle FSM as descibed in the write up
  5. class LightCycle(StateMachineProgram):
  6.     $setup {
  7.         #Set lights to their initial state
  8.         StateNode() =N=> {startred, startblue, startgreen}
  9.  
  10.         startred:  SetLights(cube1, red_light)
  11.         startgreen: SetLights(cube2, green_light)
  12.         startblue: SetLights(cube3, blue_light)
  13.        
  14.         #Run the first light cycle after a tap
  15.         {startred, startblue, startgreen} =Tap()=> {next1, next2, next3}
  16.  
  17.     next1: SetLights(cube1, green_light)
  18.         next2: SetLights(cube2, blue_light)
  19.         next3: SetLights(cube3, red_light)
  20.  
  21.         #Runs the second light cycle after a tap
  22.         {next1, next2, next3} =Tap()=> {last1, last2, last3}
  23.        
  24.         last1: SetLights(cube1, blue_light)
  25.         last2: SetLights(cube2, red_light)
  26.         last3: SetLights(cube3, green_light)
  27.  
  28.         #Cycles back to initial colors on tap
  29.         {last1, last2, last3} =Tap()=> {startred, startblue, startgreen}
  30.  
  31.     }

Raw Paste

Login or Register to edit or fork this paste. It's free.