Repository navigation
Expand file tree
/
Copy pathlib.ino
More file actions
218 lines (202 loc) · 6.84 KB
/
Copy pathlib.ino
File metadata and controls
218 lines (202 loc) · 6.84 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
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
void _setup() {
Serial.begin(9800);
pinMode(nextButton, INPUT_PULLUP);
pinMode(speaker, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(bigE, OUTPUT);
}
void _run() {
checkStuff();
play(state);
}
void checkStuff() { // check for state change
setState();
setTempo(); // check for tempo change;
setPitch();
}
void setState() {
Serial.print("current state: ");
Serial.println(state);
Serial.print("Reading: "); Serial.println(dr(nextButton));
if(!dr(nextButton) && pressed == false) {
state ++;
if (state >= songCount) {
state = 0;
}
pressed = true;
}
else if(dr(nextButton) && pressed == true){
pressed = false;
}
}
void play(int s) {
switch (s) {
case 0: zelda(); break;
case 1: fairy(); break;
case 2: scale(); break;
case 3: dragonforce(); break;
default: break;
}
}
void setTempo() {
tempoKnob = analogRead(tempoPin);
Serial.print("Tempo Before: ");
Serial.println(tempo);
// total bits is 1024. Divide by n for n sections.
if (tempoKnob <= 64)tempo = 0.25;
if (tempoKnob >= 65 && tempoKnob <= 128)tempo = 0.3;
if (tempoKnob >= 129 && tempoKnob <= 192)tempo = 0.4;
if (tempoKnob >= 193 && tempoKnob <= 256)tempo = 0.5;
if (tempoKnob >= 257 && tempoKnob <= 320)tempo = 0.6;
if (tempoKnob >= 321 && tempoKnob <= 384)tempo = 0.7;
if (tempoKnob >= 385 && tempoKnob <= 448)tempo = 0.8;
if (tempoKnob >= 449 && tempoKnob <= 512)tempo = 0.9;
if (tempoKnob >= 513 && tempoKnob <= 576)tempo = 1;
if (tempoKnob >= 577 && tempoKnob <= 640)tempo = 1.1;
if (tempoKnob >= 641 && tempoKnob <= 704)tempo = 1.2;
if (tempoKnob >= 705 && tempoKnob <= 768)tempo = 1.3;
if (tempoKnob >= 769 && tempoKnob <= 832)tempo = 1.4;
if (tempoKnob >= 833 && tempoKnob <= 896)tempo = 1.5;
if (tempoKnob >= 897 && tempoKnob <= 960)tempo = 1.6;
if (tempoKnob >= 961)tempo = 1.7;
Serial.print("Tempo After Conversion: ");
Serial.println(tempo);
return tempo;
}
void setPitch() {
pitchKnob = analogRead(pitchPin);
//TODO add pitch knob
// total bits is 1024. Divide by n for n sections.
if (pitchKnob <= 64)pitch = 8;
if (pitchKnob >= 65 && pitchKnob <= 128)pitch = 7;
if (pitchKnob >= 129 && pitchKnob <= 192)pitch = 6;
if (pitchKnob >= 193 && pitchKnob <= 256)pitch = 5;
if (pitchKnob >= 257 && pitchKnob <= 320)pitch = 4;
if (pitchKnob >= 321 && pitchKnob <= 384)pitch = 3;
if (pitchKnob >= 385 && pitchKnob <= 448)pitch = 2;
if (pitchKnob >= 449 && pitchKnob <= 512)pitch = 1;
if (pitchKnob >= 513 && pitchKnob <= 576)pitch = 0;
if (pitchKnob >= 577 && pitchKnob <= 640)pitch = -1;
if (pitchKnob >= 641 && pitchKnob <= 704)pitch = -2;
if (pitchKnob >= 705 && pitchKnob <= 768)pitch = -3;
if (pitchKnob >= 769 && pitchKnob <= 832)pitch = -4;
if (pitchKnob >= 833 && pitchKnob <= 896)pitch = -5;
if (pitchKnob >= 897 && pitchKnob <= 960)pitch = -6;
if (pitchKnob >= 961)pitch = -7;
return pitch;
}
// Read inputs
boolean dr(int i) { // digital read pin
return digitalRead(i);
}
void lightUpNoteLED(int note){
turnOffAllLeds();
switch(note){
case NOTE_B0: dr(b, 'n'); break;
case NOTE_C1: dr(c, 'n'); break;
case NOTE_CS1: dr(c, 'n'); break;
case NOTE_D1: dr(d, 'n'); break;
case NOTE_DS1: dr(d, 'n'); break;
case NOTE_E1: dr(e, 'n'); dr(bigE, 'n'); break;
case NOTE_F1: dr(f, 'n'); break;
case NOTE_FS1: dr(f, 'n'); break;
case NOTE_G1: dr(g, 'n'); break;
case NOTE_GS1: dr(g, 'n'); break;
case NOTE_A1: dr(a, 'n'); break;
case NOTE_AS1: dr(a, 'n'); break;
case NOTE_B1: dr(b, 'n'); break;
case NOTE_C2: dr(c, 'n'); break;
case NOTE_CS2: dr(c, 'n'); break;
case NOTE_D2: dr(d, 'n'); break;
case NOTE_DS2: dr(d, 'n'); break;
case NOTE_E2: dr(e, 'n'); dr(bigE, 'n'); break;
case NOTE_F2: dr(f, 'n'); break;
case NOTE_FS2: dr(f, 'n'); break;
case NOTE_G2: dr(g, 'n'); break;
case NOTE_GS2: dr(g, 'n'); break;
case NOTE_A2: dr(a, 'n'); break;
case NOTE_AS2: dr(a, 'n'); break;
case NOTE_B2: dr(b, 'n'); break;
case NOTE_C3: dr(c, 'n'); break;
case NOTE_CS3: dr(c, 'n'); break;
case NOTE_D3: dr(d, 'n'); break;
case NOTE_DS3: dr(d, 'n'); break;
case NOTE_E3: dr(e, 'n'); dr(bigE, 'n'); break;
case NOTE_F3: dr(f, 'n'); break;
case NOTE_FS3: dr(f, 'n'); break;
case NOTE_G3: dr(g, 'n'); break;
case NOTE_GS3: dr(g, 'n'); break;
case NOTE_A3: dr(a, 'n'); break;
case NOTE_AS3: dr(a, 'n'); break;
case NOTE_B3: dr(b, 'n'); break;
case NOTE_C4: dr(c, 'n'); break;
case NOTE_CS4: dr(c, 'n'); break;
case NOTE_D4: dr(d, 'n'); break;
case NOTE_DS4: dr(d, 'n'); break;
case NOTE_E4: dr(e, 'n'); dr(bigE, 'n'); break;
case NOTE_F4: dr(f, 'n'); break;
case NOTE_FS4: dr(f, 'n'); break;
case NOTE_G4: dr(g, 'n'); break;
case NOTE_GS4: dr(g, 'n'); break;
case NOTE_A4: dr(a, 'n'); break;
case NOTE_AS4: dr(a, 'n'); break;
case NOTE_B4: dr(b, 'n'); break;
case NOTE_C5: dr(c, 'n'); break;
case NOTE_CS5: dr(c, 'n'); break;
case NOTE_D5: dr(d, 'n'); break;
case NOTE_DS5: dr(d, 'n'); break;
case NOTE_E5: dr(e, 'n'); dr(bigE, 'n'); break;
case NOTE_F5: dr(f, 'n'); break;
case NOTE_FS5: dr(f, 'n'); break;
case NOTE_G5: dr(g, 'n'); break;
case NOTE_GS5: dr(g, 'n'); break;
case NOTE_A5: dr(a, 'n'); break;
case NOTE_AS5: dr(a, 'n'); break;
case NOTE_B5: dr(b, 'n'); break;
case NOTE_C6: dr(c, 'n'); break;
case NOTE_CS6: dr(c, 'n'); break;
case NOTE_D6: dr(d, 'n'); break;
case NOTE_DS6: dr(d, 'n'); break;
case NOTE_E6: dr(e, 'n'); dr(bigE, 'n'); break;
case NOTE_F6: dr(f, 'n'); break;
case NOTE_FS6: dr(f, 'n'); break;
case NOTE_G6: dr(g, 'n'); break;
case NOTE_GS6: dr(g, 'n'); break;
case NOTE_A6: dr(a, 'n'); break;
case NOTE_AS6: dr(a, 'n'); break;
case NOTE_B6: dr(b, 'n'); break;
case NOTE_C7: dr(c, 'n'); break;
case NOTE_CS7: dr(c, 'n'); break;
case NOTE_D7: dr(d, 'n'); break;
case NOTE_DS7: dr(d, 'n'); break;
case NOTE_E7: dr(e, 'n'); dr(bigE, 'n'); break;
case NOTE_F7: dr(f, 'n'); break;
case NOTE_FS7: dr(f, 'n'); break;
case NOTE_G7: dr(g, 'n'); break;
case NOTE_GS7: dr(g, 'n'); break;
case NOTE_A7: dr(a, 'n'); break;
case NOTE_AS7: dr(a, 'n'); break;
case NOTE_B7: dr(b, 'n'); break;
case NOTE_C8: dr(c, 'n'); break;
case NOTE_CS8: dr(c, 'n'); break;
case NOTE_D8: dr(d, 'n'); break;
case NOTE_DS8: dr(d, 'n'); break;
default: break;
}
}
void turnOffAllLeds(){
for(int i = 2; i <= 9; i++){
dr(i, 'f');
}
}
// turn on/off LEDS
void dr(int i, char c) { // led, n on, f off
if (c == 'n') digitalWrite(i, HIGH); // turn on
if (c == 'f') digitalWrite(i, LOW); // turn off
}