Fixed some basic stuff and tried working around dirty signal

This commit is contained in:
əlemi 2018-11-11 02:00:08 +01:00
parent 84c9296956
commit d8e545a50c

View file

@ -42,10 +42,12 @@ byte noteBuffer;
byte velocity = 100; // Placeholder. Will need something to change it byte velocity = 100; // Placeholder. Will need something to change it
int channel = 7; // Placeholder. Will need something to change it int channel = 7; // Placeholder. Will need something to change it
int bpm = 120; // Placeholder. Will need something to change it int bpm = 120; // Placeholder. Will need something to change it
int gate = 25; // Placeholder. Will need something to change it int gate = 300; // Placeholder. Will need something to change it
int nextBeat = 0; unsigned long nextBeat = 0;
int step = 0; int step = 0;
int lastStep = 0;
boolean notePlayed = LOW;
@ -65,9 +67,34 @@ void setup()
void loop() { void loop() {
if (millis() < nextBeat) return; if (millis() < nextBeat) return;
scan(); notePlayed = LOW;
while (notePlayed == LOW) {
cleanScan();
arp(); arp();
} }
nextBeat += (MINUTE / bpm);
}
void cleanScan() {
int c;
for (c = 0; c < 49; c++) noteCounter[c] = 0;
scan();
for (c = 0; c < 49; c++) {
if (status[c] == HIGH) noteCounter[c]++;
}
scan();
for (c = 0; c < 49; c++) {
if (status[c] == HIGH) noteCounter[c]++;
}
scan();
for (c = 0; c < 49; c++) {
if (status[c] == HIGH) noteCounter[c]++;
}
for (c = 0; c < 49; c++) {
if (noteCounter[c] == 3) status[c] = HIGH;
else status[c] = LOW;
}
}
void send() { void send() {
for (int c = 48; c >= 0; c--) { for (int c = 48; c >= 0; c--) {
@ -100,6 +127,7 @@ void playNote(int c, boolean status) {
} }
void arp() { void arp() {
step++;
while (step < 49 && status[step] == LOW) { while (step < 49 && status[step] == LOW) {
step++; step++;
} }
@ -107,9 +135,10 @@ void arp() {
step = 0; step = 0;
} }
else { else {
playNote(lastStep, LOW);
playNote(step, HIGH); playNote(step, HIGH);
if (gate < millis() - nextBeat) delay(gate - 5); // 5 ms arbitrarily for the check. Need something more sofisticate lastStep = step;
playNote(step, LOW); notePlayed = HIGH;
} }
return; return;
} }