|
本帖最后由 amd_yes! 于 2022-7-23 21:55 编辑
L298N模块控制电机,四个电机一动不动,代码附下:
各位大佬,这是什么问题啊?急!
void setMotor(int in1,int in2,int ln, int _speed_)
{
if (_speed_ == 0)
{
digitalWrite(in1, HIGH);
digitalWrite(in2, HIGH);
analogWrite(ln, 0);
}
else if (_speed_ > 0)
{
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(ln, _speed_);
}
else
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(ln, _speed_);
}
}
void xiaoche(int c){
switch(c){
case 0:
setMotor(4,3,5,0);
setMotor(2,6,7,0);
case 1:
setMotor(4,3,5,100);
setMotor(2,6,7,100);
case 2:
setMotor(4,3,5,100);
setMotor(2,6,7,0);
case 3:
setMotor(4,3,5,0);
setMotor(2,6,7,100);
}
}
void setup(){
pinMode(2, OUTPUT);
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
//l298n接线
xiaoche(0);
}
void loop(){
xiaoche(1);
}
|
|