`看了官方的例程发现有个通过特殊遥控器遥控麦昆的程序,想要试用发现没有合适的遥控器,于是像测试一下电视遥控器是否可行,都是红外的感觉可以。
采用读取红外线的程序测试了一下遥控器输出的键值
通过测试,电视遥控器的键值:
1 - 5 直接识别为 1 - 5
于是更改一下遥控器操作小车程序:
- maqueen.IR_callbackUser(function ({ myparam: message }) {
- if (message == 1) {
- maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 150)
- maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 150)
- maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOn)
- maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOn)
- }
- if (message == 2) {
- maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, 150)
- maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, 150)
- maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOff)
- maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOff)
- }
- if (message == 3) {
- maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 0)
- maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 150)
- maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOn)
- maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOff)
- }
- if (message == 4) {
- maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 150)
- maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 0)
- maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOff)
- maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOn)
- }
- if (message == 5) {
- maqueen.motorStopAll()
- maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOff)
- maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOff)
- }
- })
复制代码
编译后实际运行效果还是挺好的。
`
|