|
- // 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, 下载次数: 8382)
复制代码
|
|