-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathL293_demo.ino
42 lines (38 loc) · 945 Bytes
/
L293_demo.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
/*
* L293_demo - show how the L293D can drive motors.
*
* 20131208 MJB written. (Michael J Bakula)
*/
// control pins for 'A' side of the L293D
#define OUT1A 9
#define OUT2A 10
#define led 13
int source = OUT1A;
int sink = OUT2A;
int veloc = 10;
int moment = 1000;
boolean toggle = 0;
void setup() {
pinMode(OUT1A, OUTPUT);
pinMode(OUT2A, OUTPUT);
pinMode(led,OUTPUT);
analogWrite(led, HIGH);
} // setup()
void loop() {
for (int veloc=0; veloc < 255; veloc+=5) {
analogWrite(source, veloc);
delay(30);
}
delay(moment);
for (int veloc=255; veloc > 0; veloc-=5) {
analogWrite(source, veloc);
delay(30);
}
delay(moment);
toggle = ~toggle;
digitalWrite(led, toggle);
source = toggle ? OUT2A : OUT1A; // ternary operator conditional
sink = toggle ? OUT1A : OUT2A; // -- if/else to swap sink & source
digitalWrite(sink, LOW); // just in case
} // loop()
//end L293_demo