通过接收来自键盘或其他输入设备的单字符对四轮两驱机器人的运动进行控制。
motorCom(int keyword);
按键控制机器人的运动状态和方向。
motorCom(int keyword, int speedA, int speedB);
进行前后左右的方向控制,并对其速度进行调整(需要接收字符串并对其进行处理)。
keyword:整数,按键定义'w' - 向前;'s' - 向后;'a' - 向左;'d' - 向右;' ' - 停止(空格);
speedA:整数,占空比:0(完全停止)到255(最高速)之间。
speedB:整数,占空比:0(完全停止)到255(最高速)之间。
无返回值
此例程为BOXZ Base的样例程序。
// BOXZ_Base // Demo function:The application method to drive the 2x DC motor. // Author:Leo.Zhu // Date:10 Aug, 2013 // https://github.com/leolite/BOXZ // Hardware support list // 1. DFRobot L298 Shield 2A // 2. DFRobot L293 Shield 1A // 3. Seeed Motor Shield V2.0 // 4. Adafruit Motor Drive #include "BOXZ.h" int key; void setup() { Serial.begin(9600); boxz.initMotor(); Serial.println("Hello! BOXZ!"); } void loop() { if(Serial.available() > 0) { key = Serial.read(); } boxz.motorCom(key); }