16 MOTOR_BOTH = MOTOR_LEFT | MOTOR_RIGHT
42 print '''Please, plug LEFT motor in C port, 43 RIGHT motor in B port and try again.''' 50 print '''IR remote control: 51 RED UP & BLUE UP - forward 52 RED DOWN & BLUE DOWN - backward 53 RED UP | BLUE DOWN - left 54 RED DOWN | BLUE UP - right''' 56 print '''IR sensor is NOT found, 57 use the EV3 brick buttons.''' 59 print 'Press BACK on the EV3 brick for EXIT...' 63 RED_UP_BLUE_UP : FORTH,
64 RED_DOWN_BLUE_DOWN : BACK,
66 RED_UP_BLUE_DOWN : LEFT,
69 RED_DOWN_BLUE_UP : RIGHT,
73 def coro_handle_ir_control():
75 Coroutine of IR remote control handling. 79 if ir == SOCKET__NONE_:
84 pressed = btns = IR_REMOTE__NONE_
87 while btns == pressed:
93 if pressed
in IR_ACTIONS:
94 command = IR_ACTIONS[ pressed ]
103 EV3_KEY_RIGHT : RIGHT,
106 def coro_handle_brick_control():
108 Coroutine of the EV3 brick keys handling. 110 global command, alive
112 pressed = keys = EV3_KEY__NONE_
115 while keys == pressed:
121 if pressed
in KEY_ACTIONS:
122 command = KEY_ACTIONS[ pressed ]
125 if pressed == EV3_KEY_BACK:
131 Coroutine of control the motors. 133 speed_linear = max_speed * SPEED_LINEAR / 100
134 speed_circular = max_speed * SPEED_CIRCULAR / 100
139 while state == command:
148 elif command == FORTH:
152 elif command == BACK:
156 elif command == LEFT:
161 elif command == RIGHT:
169 if __name__ ==
'__main__':
170 print 'Waiting the EV3 brick online...' 173 print '*** ( EV3 ) Hello! ***' 176 handle_ir_control = coro_handle_ir_control()
177 handle_brick_control = coro_handle_brick_control()
181 handle_ir_control.next()
182 handle_brick_control.next()
188 print '*** ( EV3 ) Bye! ***'