-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmotorcode.ino
More file actions
70 lines (60 loc) · 1.31 KB
/
motorcode.ino
File metadata and controls
70 lines (60 loc) · 1.31 KB
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
61
62
63
64
65
66
67
68
69
70
// put global scope constants here
const int enableMotor = 3; // connect to enable1 (EN1) pin of L293d
const int inputPin1 = 4; // connect to IN1 pin of L293d
const int inputPin2 = 7; // connect to IN2 pin of L293d
void setup() {
// put your setup code here, to run once:
pinMode(enableMotor, OUTPUT);
pinMode(inputPin1, OUTPUT);
pinMode(inputPin2, OUTPUT);
// initially turn off motors
digitalWrite(inputPin1, LOW);
digitalWrite(inputPin2, LOW);
}
void brake() {
digitalWrite(inputPin1, LOW);
digitalWrite(inputPin2, LOW);
}
void movefwd() {
digitalWrite(inputPin1, HIGH);
digitalWrite(inputPin2, LOW);
}
void movebwd() {
digitalWrite(inputPin1, LOW);
digitalWrite(inputPin2, HIGH);
}
void speedUpfwd() {
movefwd();
for (int i = 0; i < 256; i++) {
analogWrite(enableMotor, i);
delay(50);
}
}
void speedUpbwd() {
movebwd();
for (int i = 0; i < 256; i++) {
analogWrite(enableMotor, i);
delay(50);
}
}
void speedDownfwd() {
movefwd();
for (int i = 255; i >= 0; i--) {
analogWrite(enableMotor, i);
delay(50);
}
}
void speedDownbwd() {
movebwd();
for (int i = 255; i >= 0; i--) {
analogWrite(enableMotor, i);
delay(50);
}
}
void loop() {
// put your main code here, to run repeatedly:
speedUpfwd();
delay(1000);
speedDownfwd();
delay(1000);
}