-
Notifications
You must be signed in to change notification settings - Fork 0
/
MotorControl_Two_Direction.ino
190 lines (164 loc) · 3.35 KB
/
MotorControl_Two_Direction.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Code for Hardware Presentation 1, 2/23/2017
// Junior Design, EGR 3380
// Team 15 - Ricky Bobby and the Washing Machine
// operates motor with h-bridge using button
// initially motor is stoppped,
// pressing button causes motor to push washers forward in arm
// pressing button again stops motor
// pressing again causes motor to rotate in opposite direction
// pressing again causes motor to stop
// repeats
#define buttonIn 10
#define hBin1 11
#define hBin2 12
#define hBen 13
void motOpChange(int enVal, int hBoutPinVal1, int hBoutPinVal2);
void setup()
{
pinMode(3, OUTPUT);
pinMode(4, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop()
{
/*
int enVal;
int hBoutPinVal1;
int hBoutPinVal2;
enVal = HIGH;
hBoutPinVal1 = LOW;
hBoutPinVal2 = HIGH;
digitalWrite(hBen, enVal);
digitalWrite(hBin1, hBoutPinVal1);
digitalWrite(hBin2, hBoutPinVal2);
delay(1000);
enVal = HIGH;
hBoutPinVal1 = HIGH;
hBoutPinVal2 = LOW;
digitalWrite(hBen, enVal);
digitalWrite(hBin1, hBoutPinVal1);
digitalWrite(hBin2, hBoutPinVal2);
delay(1000);
*/
/*
digitalWrite(hBen, HIGH);
digitalWrite(hBin1, HIGH);
digitalWrite(hBin2, LOW);
delay(1000);
digitalWrite(hBen, HIGH);
digitalWrite(hBin1, LOW);
digitalWrite(hBin2, HIGH);
delay(1000);
*/
/*
motOpChange(LOW, HIGH, LOW);
motOpChange(HIGH, LOW, HIGH);
motOpChange(LOW, LOW, HIGH);
motOpChange(HIGH, HIGH, LOW);
*/
/*
motOpChange(LOW, HIGH, LOW);
motOpChange(HIGH, HIGH, LOW);
motOpChange(LOW, LOW, HIGH);
motOpChange(HIGH, HIGH, LOW);
*/
/*
digitalWrite(hBen, HIGH);
digitalWrite(hBin1, LOW);
digitalWrite(hBin2, HIGH);
// wait for next pressing of button
while (digitalRead(buttonIn) == LOW)
{
if (digitalRead(buttonIn) == LOW)
{
break;
}
}
// wait for button to be released
while (digitalRead(buttonIn) == HIGH)
{
if (digitalRead(buttonIn) == HIGH)
{
break;
}
}
digitalWrite(hBen, LOW);
digitalWrite(hBin1, HIGH);
digitalWrite(hBin2, LOW);
// wait for next pressing of button
while(digitalRead(buttonIn) == LOW)
{
}
// wait for button to be released
while(digitalRead(buttonIn) == HIGH)
{
}
*/
/*
if(digitalRead(4) == HIGH)
{
digitalWrite(3, HIGH);
}
else
{
digitalWrite(3, LOW);
}
*/
/*
if(digitalRead(buttonIn))
{
}
*/
digitalWrite(13, LOW);
delay(10);
digitalWrite(13, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
delay(10);
digitalWrite(13, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
delay(10);
/*
if(digitalRead(10) == HIGH)
{
digitalWrite(13, LOW);
}
else
{
digitalWrite(13, HIGH);
}
*/
}
void motOpChange(int enVal, int hBoutPinVal1, int hBoutPinVal2)
{
// set desired motor operation
digitalWrite(hBen, enVal);
digitalWrite(hBin1, hBoutPinVal1);
digitalWrite(hBin2, hBoutPinVal2);
// wait for next pressing of button
if(enVal == HIGH)
{
while(digitalRead(buttonIn) == HIGH)
{
digitalWrite(hBen, HIGH);
/* delay(5);
digitalWrite(hBen, LOW);
delay(5);*/
}
}
else
{
while(digitalRead(buttonIn) == HIGH)
{
}
}
// wait for button to be released
while(digitalRead(buttonIn) == LOW)
{
delay(100);
}
}