//define pin name
#define dir 1 // Direction
#define pwrA 2 // Power for Motor A
#define pwrB 4 // Power for Motor B
#define pwrC 7 // Power for Motor C
//constants won't change
const int buttonPin = 8; // the number of the pushbutton pin
// variables will change
int buttonState = 0; // variable for reading the pushbutton status
int pwrAState = LOW;
int pwrBState = LOW;
int pwrcState = LOW;
int delaymillsA = 400;
int delaymillsAr = 400; // Return delay
int delaymillsB = 400;
int delaymillsBr = 400; // Return delay
int delaymillsC = 500;
int delaymillsCr = 500; // Return delay
int delaymillsD = 100;
void setup() {
// initialize the pwr and dir pins as outputs:
pinMode(pwrA,OUTPUT);
pinMode(pwrB,OUTPUT);
pinMode(pwrC,OUTPUT);
pinMode(dir,OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
digitalWrite(pwrA,HIGH);
digitalWrite(dir,HIGH); // set DIR pin HIGH or LOW
delay(delaymillsA);
digitalWrite(dir,LOW); // set DIR pin HIGH or LOW
delay(delaymillsAr);
digitalWrite(pwrA,LOW);
delay(delaymillsD);
digitalWrite(pwrB,HIGH);
digitalWrite(dir,HIGH); // set DIR pin HIGH or LOW
delay(delaymillsB);
digitalWrite(dir,LOW); // set DIR pin HIGH or LOW
delay(delaymillsBr);
digitalWrite(pwrB,LOW);
delay(delaymillsD);
digitalWrite(pwrC,HIGH);
digitalWrite(dir,HIGH); // set DIR pin HIGH or LOW
delay(delaymillsC);
digitalWrite(dir,LOW); // set DIR pin HIGH or LOW
delay(delaymillsCr);
digitalWrite(pwrC,LOW);
delay(delaymillsD);
} else {
// turn LED off:
digitalWrite(pwrA, LOW);
digitalWrite(pwrB, LOW);
digitalWrite(pwrC, LOW);
}
}
Comments