# variables for state var state[4] = [0,0,0,0] var new_state[4] = [0,0,0,0] # reset outputs call sound.system(-1) call leds.top(0,0,0) call leds.bottom.left(0,0,0) call leds.bottom.right(0,0,0) call leds.circle(0,0,0,0,0,0,0,0) # subroutine to display the current state sub display_state call leds.circle(0,state[1]*32,0,state[3]*32,0,state[2]*32,0,state[0]*32) onevent buttons when button.forward == 1 do motor.left.target = 100 motor.right.target = 100 emit pair_run 0 end call math.copy(state, new_state) callsub display_state onevent prox when prox.ground.delta[0] >= 425 do motor.left.target = 50 motor.right.target = 150 emit pair_run 1 end when prox.ground.delta[0] <= 250 do motor.left.target = 150 motor.right.target = 50 emit pair_run 2 end when prox.ground.delta[0] >= 250 and prox.ground.delta[0] <= 425 do motor.left.target = 100 motor.right.target = 100 emit pair_run 3 end call math.copy(state, new_state) callsub display_state