四博智联产品售后
标题:
2路电机控制Arduino代码示例
[打印本页]
作者:
ycf
时间:
2015-12-10 10:56
标题:
2路电机控制Arduino代码示例
// By DOIT,http://www.doit.am
/*
For Channel A and Chanel B,
Motor rotates forward, then backward,.....
Pins:
PWMB --- 12
DIRB --- 13
PWMA --- 3
DIRA --- 1
*/
int pwm1 = 3;
int dir1 = 1;
int pwm2 = 12;
int dir2 = 13;
void setup()
{
pinMode(dir1, OUTPUT);
pinMode(dir2, OUTPUT);
}
void loop()
{
int value;
for(value = 0 ; value<=255; value+=5) // forward,speed up
{
digitalWrite(dir1,HIGH);
digitalWrite(dir2,HIGH);
analogWrite(pwm1, value); //PWM Speed Control
analogWrite(pwm2 , value); //PWM Speed Control
delay(30);
}
for(value = 255 ; value >=0; value-=5) // forward,speed down
{
digitalWrite(dir1,HIGH);
digitalWrite(dir2,HIGH);
analogWrite(pwm1, value); //PWM Speed Control
analogWrite(pwm2 , value); //PWM Speed Control
delay(30);
}
delay(2000);
for(value = 0 ; value<=255; value+=5) // backward,speed up
{
digitalWrite(dir1,LOW);
digitalWrite(dir2,LOW);
analogWrite(pwm1, value); //PWM Speed Control
analogWrite(pwm2 , value); //PWM Speed Control
delay(30);
}
for(value = 255 ; value >=0; value-=5) // backward,speed down
{
digitalWrite(dir1,LOW);
digitalWrite(dir2,LOW);
analogWrite(pwm1, value); //PWM Speed Control
analogWrite(pwm2 , value); //PWM Speed Control
delay(30);
}
delay(3000);
}
MotorControlSample.zip
(773 Bytes, 下载次数: 8377)
2015-12-10 10:56 上传
点击文件名下载附件
复制代码
欢迎光临 四博智联产品售后 (http://115.29.109.104/)
Powered by Discuz! X3.2