9.9 Example: motorReverser

/* motorReverser
This script will cause the motor to spin in 
one direction for five seconds then spin in the other direction 
for three seconds, then repeat. */

#define MOTORA1 13
#define MOTORA2 12

void setup(){
pinMode(MOTORA1, OUTPUT);
pinMode(MOTORA2, OUTPUT);
}

void loop(){
digitalWrite(MOTORA1, HIGH);
digitalWrite(MOTORA2, LOW);
delay(5000);
digitalWrite(MOTORA1, LOW);
digitalWrite(MOTORA2, HIGH);
delay(3000);
}

License

Icon for the Creative Commons Attribution 4.0 International License

Applied Electrical Engineering Fundamentals by David J. McLaughlin is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book