# variables for state var state[4] = [0,0,0,0] var new_state[4] = [0,0,0,0] # stop timer 0 timer.period[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 new_state[0] = 1 new_state[1] = 0 motor.left.target = 500 motor.right.target = 500 call leds.top(0,32,0) emit pair_run 0 _emit debug_log [0, 0x5, 0x8d71, 0x90, 0, 0x10, 0, 0x2d, 0x1414, 0x420] end when button.center == 1 do new_state[0] = 0 new_state[1] = 0 motor.left.target = 0 motor.right.target = 0 call leds.top(0,0,0) emit pair_run 1 _emit debug_log [0x1, 0x5, 0x8d71, 0x90, 0, 0x1, 0, 0x48, 0xa0a, 0] end call math.copy(state, new_state) callsub display_state onevent prox when prox.horizontal[0] >= 2000 and prox.horizontal[1] <= 1000 and prox.horizontal[2] <= 1000 and prox.horizontal[3] <= 1000 do if state[0] == 1 and state[1] == 0 then motor.left.target = 500 motor.right.target = 300 call leds.top(32,31,0) emit pair_run 2 _emit debug_log [0x2, 0x4, 0x9872, 0x1a80, 0x3e8, 0x7d0, 0x2d, 0x1410, 0x8c1f] end end when prox.horizontal[0] >= 2000 and prox.horizontal[1] >= 2000 do if state[0] == 1 and state[1] == 1 then motor.left.target = 350 motor.right.target = 100 call leds.top(32,17,0) emit pair_run 3 _emit debug_log [0x3, 0x4, 0x9872, 0x1400, 0x3e8, 0x7d0, 0x24, 0x110c, 0x8a51] end end when prox.horizontal[1] <= 1000 and prox.horizontal[2] <= 1000 and prox.horizontal[3] <= 1000 and prox.horizontal[4] >= 2000 do if state[0] == 1 and state[1] == 0 then motor.left.target = 300 motor.right.target = 500 call leds.top(32,32,0) emit pair_run 4 _emit debug_log [0x4, 0x4, 0x9872, 0xa90, 0x3e8, 0x7d0, 0x2d, 0x1014, 0x8c40] end end when prox.horizontal[3] >= 2000 and prox.horizontal[4] >= 2000 do if state[0] == 1 and state[1] == 0 then motor.left.target = 100 motor.right.target = 350 call leds.top(32,14,0) emit pair_run 5 _emit debug_log [0x5, 0x4, 0x9872, 0x50, 0x3e8, 0x7d0, 0x2d, 0xc11, 0x89ee] end end when prox.horizontal[2] >= 2000 and prox.horizontal[3] >= 2000 do if state[0] == 1 and state[1] == 0 then motor.left.target = -100 motor.right.target = 200 call leds.top(32,0,0) emit pair_run 6 _emit debug_log [0x6, 0x4, 0x9872, 0x140, 0x3e8, 0x7d0, 0x2d, 0x80e, 0x8820] end end when prox.horizontal[1] >= 2000 and prox.horizontal[2] >= 2000 do if state[0] == 1 and state[1] == 0 then motor.left.target = 200 motor.right.target = -100 call leds.top(0,0,32) emit pair_run 7 _emit debug_log [0x7, 0x4, 0x9872, 0x500, 0x3e8, 0x7d0, 0x2d, 0xe08, 0x20] end end when prox.horizontal[1] <= 1000 and prox.horizontal[2] <= 1000 and prox.horizontal[3] <= 1000 do if state[0] == 1 and state[1] == 0 then motor.left.target = 500 motor.right.target = 500 call leds.top(0,32,0) emit pair_run 8 _emit debug_log [0x8, 0x4, 0x9872, 0xa80, 0x3e8, 0x7d0, 0x2d, 0x1414, 0x420] end end when prox.horizontal[0] >= 2000 and prox.horizontal[1] >= 2000 and prox.horizontal[2] >= 2000 and prox.horizontal[3] >= 2000 and prox.horizontal[4] >= 2000 do if state[0] == 1 and state[1] == 0 then motor.left.target = -500 motor.right.target = 500 timer.period[0] = 1000 new_state[1] = 1 call leds.top(32,0,32) emit pair_run 9 _emit debug_log [0x9, 0x6, 0xc872, 0x9d0, 0x1550, 0x3e8, 0x7d0, 0x2d, 0x14, 0x3e8, 0x9, 0x8840] end end call math.copy(state, new_state) callsub display_state onevent timer0 timer.period[0] = 0 if state[0] == 1 and state[1] == 1 then motor.left.target = 500 motor.right.target = 500 call leds.top(0,32,0) new_state[1] = 0 emit pair_run 10 _emit debug_log [0xa, 0x5, 0x9876, 0xd0, 0x24, 0x1414, 0x420, 0x12] end call math.copy(state, new_state) callsub display_state