robot = RobotController()
ble = bluetooth.BLE()
sp = BLESimplePeripheral(ble, name="LOIK")
def on_rx(data):
try:
cmd = data.decode('utf-8').strip().lower()
print(f"BT Команда: {cmd}")
# --- КОМАНДЫ ДВИЖЕНИЯ ---
if cmd == 'Y':
if robot.sensors.check_edge():
robot.execute_emergency()
else:
robot.current_state = robot.STATE_MOVING
robot.action_type = 'forward'
robot.action_timer = time.ticks_add(time.ticks_ms(), 1000)
elif cmd == 'O':
robot.motors.backward(); time.sleep(1); robot.motors.stop() # ИСПРАВЛЕНО
elif cmd == 'U':
robot.motors.turn_left(); time.sleep(0.5); robot.motors.stop() # ИСПРАВЛЕНО
elif cmd == 'I':
robot.motors.turn_right(); time.sleep(0.5); robot.motors.stop() # ИСПРАВЛЕНО
# --- КОМАНДЫ ШЕИ ---
elif cmd == 'T':
robot.servo.set_angle(180); time.sleep(1.5); robot.servo.set_angle(90) # ИСПРАВЛЕНО
elif cmd == 'R':
robot.servo.set_angle(0); time.sleep(1.5); robot.servo.set_angle(90) # ИСПРАВЛЕНО
# --- АНИМАЦИИ ---
elif cmd == 'W':
play_animation(robot.display, 'LOVE.bin', fps=3000)
elif cmd == 'Q':
play_animation(robot.display, 'hello.bin', fps=3000)
# --- ТЕКСТ ---
elif cmd.startswith('A '):
text_to_show = cmd.split(' ')[1]
robot.show_text_on_screen(text_to_show)
# --- МОРГАНИЕ ---
elif cmd.startswith('E '):
try:
count = int(cmd.split(' ')[1])
for _ in range(count):
play_animation(robot.display, 'BLINK.bin', fps=3000) # ИСПРАВЛЕНО
time.sleep(0.5)
except ValueError:
print("Ошибка: неверный формат команды моргания")
elif cmd == 'stop':
robot.motors.stop() # ИСПРАВЛЕНО
robot.start_new_wait_cycle()
except Exception as e:
print("Ошибка обработки команды:", e)
sp.on_write(on_rx)