【EV3】遥控小车

这是个用遥控器控制一个小车的程序,用红外传感器来接收遥控器,左上按键左转(左轮不动,右轮动),右上按键右转(左轮动,右轮不动),左下和右下按键直退。

 

from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
brick.sound.beep()
infra_sensor = InfraredSensor(Port.S3)
white_motor = Motor(Port.D)
red_motor = Motor(Port.A)
print(Button.LEFT_UP)
while True:
    buttons = infra_sensor.buttons(1)
    print(buttons)
    if Button.LEFT_UP in buttons and Button.RIGHT_UP in buttons:
        white_motor.run(1000)
        red_motor.run(1000)
    elif Button.LEFT_UP in buttons:
        white_motor.run(1000)
        red_motor.run(0)
    elif Button.RIGHT_UP in buttons:
        white_motor.run(0)
        red_motor.run(1000)
    elif Button.LEFT_DOWN in buttons or Button.RIGHT_DOWN in buttons:
        white_motor.run(-1000)
        red_motor.run(-1000)
    wait(100)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值