You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
966 B
50 lines
966 B
3 years ago
|
//www.elegoo.com
|
||
|
//2016.12.12
|
||
|
|
||
|
/************************
|
||
|
Exercise the motor using
|
||
|
the L293D chip
|
||
|
************************/
|
||
|
|
||
|
#define ENABLE 5
|
||
|
#define DIRA 3
|
||
|
#define DIRB 4
|
||
|
|
||
|
int i;
|
||
|
|
||
|
void setup() {
|
||
|
//---set pin direction
|
||
|
pinMode(ENABLE,OUTPUT);
|
||
|
pinMode(DIRA,OUTPUT);
|
||
|
pinMode(DIRB,OUTPUT);
|
||
|
Serial.begin(9600);
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
|
||
|
//---back and forth example
|
||
|
Serial.println("One way, then reverse");
|
||
|
digitalWrite(ENABLE,HIGH); // enable on
|
||
|
for (i=0;i<5;i++) {
|
||
|
digitalWrite(DIRA,HIGH); //one way
|
||
|
digitalWrite(DIRB,LOW);
|
||
|
delay(750);
|
||
|
digitalWrite(DIRA,LOW); //reverse
|
||
|
digitalWrite(DIRB,HIGH);
|
||
|
delay(750);
|
||
|
}
|
||
|
digitalWrite(ENABLE,LOW); // disable
|
||
|
delay(3000);
|
||
|
for (i=0;i<5;i++) {
|
||
|
digitalWrite(DIRA,HIGH); //one way
|
||
|
digitalWrite(DIRB,LOW);
|
||
|
delay(750);
|
||
|
digitalWrite(DIRA,LOW); //reverse
|
||
|
digitalWrite(DIRB,HIGH);
|
||
|
delay(750);
|
||
|
}
|
||
|
digitalWrite(ENABLE,LOW); // disable
|
||
|
delay(3000);
|
||
|
}
|
||
|
|