小曼机器人底部有两个电机,左右各一个,通过左右电机不同旋转方向的组合,即可实现机器人的前进、后退、左转、右转、停止。
机器人前进:
void loop() {
//左电机逆时针旋转
analogWrite(myMotorL[0],0);
analogWrite(myMotorL[1],255);
//右电机顺时针旋转
analogWrite(myMotorR[0],0);
analogWrite(myMotorR[1],255);
}
机器人后退:
void loop() {
//左电机顺时针旋转
analogWrite(myMotorL[0],255);
analogWrite(myMotorL[1],0);
//右电机逆时针旋转
analogWrite(myMotorR[0],255);
analogWrite(myMotorR[1],0);
}
机器人左转:
void loop() {
//左电机顺时针旋转
analogWrite(myMotorL[0],255);
analogWrite(myMotorL[1],0);
//右电机顺时针旋转
analogWrite(myMotorR[0],0);
analogWrite(myMotorR[1],255);
}
机器人右转:
void loop() {
//左电机逆时针旋转
analogWrite(myMotorL[0],0);
analogWrite(myMotorL[1],255);
//右电机逆时针旋转
analogWrite(myMotorR[0],255);
analogWrite(myMotorR[1],0);
}
机器人停止:
void loop() {
//左电机停止转动
analogWrite(myMotorL[0],0);
analogWrite(myMotorL[1],0);
//右电机停止转动
analogWrite(myMotorR[0],0);
analogWrite(myMotorR[1],0);
}(www.xing528.com)
机器人前进:
void loop() {
//左电机逆时针旋转
analogWrite(myMotorL[0],0);
analogWrite(myMotorL[1],255);
//右电机顺时针旋转
analogWrite(myMotorR[0],0);
analogWrite(myMotorR[1],255);
}
机器人后退:
void loop() {
//左电机顺时针旋转
analogWrite(myMotorL[0],255);
analogWrite(myMotorL[1],0);
//右电机逆时针旋转
analogWrite(myMotorR[0],255);
analogWrite(myMotorR[1],0);
}
机器人左转:
void loop() {
//左电机顺时针旋转
analogWrite(myMotorL[0],255);
analogWrite(myMotorL[1],0);
//右电机顺时针旋转
analogWrite(myMotorR[0],0);
analogWrite(myMotorR[1],255);
}
机器人右转:
void loop() {
//左电机逆时针旋转
analogWrite(myMotorL[0],0);
analogWrite(myMotorL[1],255);
//右电机逆时针旋转
analogWrite(myMotorR[0],255);
analogWrite(myMotorR[1],0);
}
机器人停止:
void loop() {
//左电机停止转动
analogWrite(myMotorL[0],0);
analogWrite(myMotorL[1],0);
//右电机停止转动
analogWrite(myMotorR[0],0);
analogWrite(myMotorR[1],0);
}
免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。