/
motorDriver_final3.ino
236 lines (183 loc) · 4.28 KB
/
motorDriver_final3.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// motor driver pins
int headPin = 3;
int bodyPin = 11;
int tom1 = 7;
int tom2 = 10;
//pager motors pins
int rightArm = 4;
int leftArm = 5;
int tubeArm = 6;
//shield extra pins
int headDir = 13;
int bodyDir = 12;
int headBrake = 8;
int bodyBrake = 9;
//states
int headState = LOW;
int bodyState = LOW;
int tom1State = LOW;
int tom2State = LOW;
int gongState = LOW;
int rimState = LOW;
int tubeState = LOW;
//intervals
long bodyTime;
long gongTime;
long rimTime;
long headTime;
long tomTime;
long tubeTime;
//previousesesess
long body;
long gong;
long rim;
long head;
long tom;
long tube;
//state vars
boolean bodying;
boolean gonging;
boolean rimming;
boolean heading;
boolean tomming;
boolean tubing;
//overall time interval
long beats;
//controls
int pots[] = {
A8, A9, A10, A11, A12, A13};
float potVal[6];
void setup(){
Serial.begin(9600);
pinMode(headDir, OUTPUT);
pinMode(bodyDir, OUTPUT);
pinMode(rightArm, OUTPUT);
pinMode(leftArm, OUTPUT);
pinMode(bodyPin, OUTPUT);
pinMode(headPin, OUTPUT);
pinMode(tom1, OUTPUT);
pinMode(tom2, OUTPUT);
pinMode(tubeArm, OUTPUT);
for (int i=0;i<6;i++){
pinMode(pots[i], INPUT_PULLUP);
potVal[i] = 1;
}
digitalWrite(headBrake, LOW);
digitalWrite(bodyBrake, LOW);
beats = 1000;
bodyTime = 200;
gongTime = 100;
rimTime = 100;
headTime = 200;
tomTime = 200;
tubeTime = 200;
body = 0;
gong = 0;
rim = 0;
head = 0;
tom = 0;
tube = 0;
heading = false;
bodying = false;
gonging = false;
rimming = false;
tomming = false;
tubing = false;
}
void loop(){
readPots();
long unsigned current = millis();
//*******!!!!!
//COLONEL CLANK
//*!*@@#)@*#$)@#)%@)
//HEAD!!!!!-----BUCKET, BLACK HOLE?!
if(current - head > potVal[0]){
head = current;
headState = HIGH;
heading = true;
digitalWrite(headDir, headState); //Sets direction of CH A
analogWrite(headPin, 255); //Moves CH A
}
if(heading && current - head > headTime){
heading = false;
headState=LOW;
digitalWrite(headDir, headState); //Sets direction of CH A
analogWrite(headPin, 255); //Moves CH A
}
//TOM TOM!!! MARBLES?!
if(current - tom > potVal[1]){
tom = current;
tom1State = HIGH;
tom2State = LOW;
tomming = true;
digitalWrite(tom1, tom1State); //Sets direction of CH A
digitalWrite(tom2, tom2State); //Moves CH A
}
if(tomming && current - tom > tomTime){
tomming = false;
tom1State = LOW;
tom2State = HIGH;
digitalWrite(tom1, tom1State); //Sets direction of CH A
digitalWrite(tom2, tom2State); //Moves CH A
}
//TUUUUUUUUUBEEEE ARMM!!!!!
if(current - tube > potVal[2]){
tube = current;
tubeState=HIGH;
tubing = true;
digitalWrite(tubeArm, tubeState); //Sets direction of CH A
}
if(tubing && current - tube > tubeTime){
tubing = false;
tubeState=LOW;
digitalWrite(tubeArm, tubeState); //Sets direction of CH A
}
//________________________________________________
// GONGZILLA
//________________________________
//GONG!!!!!!!!!!
if(current - gong > potVal[3]){
gong = current;
gongState=HIGH;
gonging = true;
digitalWrite(rightArm, gongState); //Sets direction of CH A
}
if(gonging && current - gong > gongTime){
gonging = false;
gongState=LOW;
digitalWrite(rightArm, gongState); //Sets direction of CH A
}
//rimshoooootttt
if(current - rim > potVal[4]){
rim = current;
rimState=HIGH;
rimming = true;
digitalWrite(leftArm, rimState); //Sets direction of CH A
}
if(rimming && current - rim > rimTime){
rimming = false;
rimState=LOW;
digitalWrite(leftArm, rimState); //Sets direction of CH A
}
//KICKDRUM!!!!!
if(current - body > potVal[5]){
body = current;
bodyState = HIGH;
bodying = true;
digitalWrite(bodyDir, bodyState); //Sets direction of CH A
analogWrite(bodyPin, 255); //Moves CH A
}
if(bodying && current - body > bodyTime){
bodying = false;
bodyState=LOW;
digitalWrite(bodyDir, bodyState); //Sets direction of CH A
analogWrite(bodyPin, 255); //Moves CH A
}
}
void readPots(){
for (int i=0;i<6;i++){
float val = analogRead(pots[i]);
float mappedVal = map(val, 14, 230, 6,100);
potVal[i] = mappedVal/28 *beats;
}
}