8413| 4
|
[求助] Arduino板控制不了马达,马达不动 |
代码: const int negR=4; const int posR=5; const int negL=6; const int posL=7; const int pwmR=9; const int pwmL=10; void setup() { pinMode(posR,OUTPUT); pinMode(negR,OUTPUT); pinMode(posL,OUTPUT); pinMode(negL,OUTPUT); pinMode(pwmR,OUTPUT); pinMode(pwmL,OUTPUT); } void loop() { forward(190,200); delay(2000); pause(0,0); delay(2000); back(190,200); delay(2000); pause(0,0); delay(2000); } void forward(byte RmotorSpeed, byte LmotorSpeed) { analogWrite(pwmR,RmotorSpeed); analogWrite(pwmL,LmotorSpeed); digitalWrite(posR,HIGH); digitalWrite(negR,LOW); digitalWrite(posL,LOW); digitalWrite(negL,HIGH); } void back(byte RmotorSpeed, byte LmotorSpeed) { analogWrite(pwmR,RmotorSpeed); analogWrite(pwmL,LmotorSpeed); digitalWrite(posR,LOW); digitalWrite(negR,HIGH); digitalWrite(posL,HIGH); digitalWrite(negL,LOW); } void pause(byte RmotorSpeed, byte LmotorSpeed) { analogWrite(pwmR,RmotorSpeed); analogWrite(pwmL,LmotorSpeed); digitalWrite(posR,LOW); digitalWrite(negR,LOW); digitalWrite(posL,LOW); digitalWrite(negL,LOW); } |
实品图
实品图
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed