forked from hadefuwa/elegoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DC_Motor2.ino
60 lines (53 loc) · 1.25 KB
/
DC_Motor2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//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() {
Serial.println("Start The Motors!");
//---PWM example, full speed then slow
for (i=255;i>100;i--) {
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
analogWrite(ENABLE,i); //enable on
delay(200);
}
for (i=100;i<255;i++) {
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
analogWrite(ENABLE,i); //enable on
delay(200);
}
/*
analogWrite(ENABLE,255); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,50); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,255); //half speed
delay(2000);
digitalWrite(ENABLE,LOW); //all done
delay(10000);
*/
}