Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int motorAdir = 8;
- int motorApwm = 9;
- int motorBdir = 11;
- int motorBpwm = 10;
- int forward = 1;
- int backward = 0;
- int delayTime = 100;//increase this if you want the change in speed to be slower
- //decrease if you want the change in speed to be faster
- void setup()
- {
- // put your setup code here, to run once:
- pinMode(motorAdir, OUTPUT);
- pinMode(motorBdir, OUTPUT);
- pinMode(motorApwm, OUTPUT);
- pinMode(motorBpwm, OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- digitalWrite(motorAdir, forward); //we declared forward up top
- digitalWrite(motorBdir, forward);
- for (byte i = 0; i <= 255; i++) {//start at 0 and increase to 255
- analogWrite(motorApwm, i);
- analogWrite(motorBpwm, i);
- Serial.print("Forward: ");Serial.println(i);
- delay(delayTime); //again delayTime is up top
- }
- //By now the PWM values for both motors are 255, max speed.
- delay(delayTime);
- for (byte i = 255; i >= 0; i--) {//start at 255 and go down to 0
- analogWrite(motorApwm, i);
- analogWrite(motorBpwm, i);
- Serial.print("Forward: ");Serial.println(i);
- delay(delayTime);
- }
- delay(delayTime);
- //Now we do the same but backwards
- digitalWrite(motorAdir, backward); //we declared forward up top
- digitalWrite(motorBdir, backward);
- for (byte i = 0; i <= 255; i++) {//start at 0 and increase to 255
- analogWrite(motorApwm, i);
- analogWrite(motorBpwm, i);
- Serial.print("Backward: ");Serial.println(i);
- delay(delayTime); //again delayTime is up top
- }
- //By now the PWM values for both motors are 255, max speed.
- delay(delayTime);
- for (byte i = 255; i >= 0; i--) {//start at 255 and go down to 0
- analogWrite(motorApwm, i);
- analogWrite(motorBpwm, i);
- Serial.print("Backward: ");Serial.println(i);
- delay(delayTime);
- }
- delay(delayTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement