5、按键控制小车前进、后退与旋转
#MicroPython动手做(24)——掌控板之拓展掌控宝
#按键控制小车前进、后退与旋转
#MicroPython动手做(24)——掌控板之拓展掌控宝
#按键控制小车前进、后退与旋转
import parrot
from mpython import *
def forward():
parrot.set_speed(parrot.MOTOR_1, 80)
parrot.set_speed(parrot.MOTOR_2, 80)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Forward.pbm', 0), 32, 0)
oled.show()
def retreat():
parrot.set_speed(parrot.MOTOR_1, -80)
parrot.set_speed(parrot.MOTOR_2, -80)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Backward.pbm', 0), 32, 0)
oled.show()
def right():
parrot.set_speed(parrot.MOTOR_1, 80)
parrot.set_speed(parrot.MOTOR_2, -80)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Right.pbm', 0), 32, 0)
oled.show()
import time
def on_button_a_down(_):
global aaa
time.sleep_ms(10)
if button_a.value() == 1: return
rgb.fill((int(0), int(102), int(0)))
rgb.write()
time.sleep_ms(1)
forward()
time.sleep(2)
Left()
time.sleep(1)
retreat()
time.sleep(2)
right()
time.sleep(1)
oled.fill(0)
parrot.set_speed(parrot.MOTOR_1, 0)
parrot.set_speed(parrot.MOTOR_2, 0)
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
oled.show()
def Left():
parrot.set_speed(parrot.MOTOR_1, -80)
parrot.set_speed(parrot.MOTOR_2, 80)
oled.fill(0)
oled.blit(image_picture.load('face/Information/Left.pbm', 0), 32, 0)
oled.show()
image_picture = Image()
button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)
|