2018-10-31 17:18:50 +01:00
|
|
|
#define C 22
|
|
|
|
#define Db 24
|
|
|
|
#define D 26
|
|
|
|
#define Eb 28
|
|
|
|
#define E 30
|
|
|
|
#define F 32
|
|
|
|
#define Gb 34
|
|
|
|
#define G 36
|
|
|
|
#define Ab 38
|
|
|
|
#define A 40
|
|
|
|
#define Bb 42
|
|
|
|
#define B 44
|
|
|
|
#define testLed 13
|
|
|
|
|
|
|
|
#define Oct1 12
|
|
|
|
#define Oct2 9
|
|
|
|
#define Oct3 8
|
|
|
|
#define Oct4 10
|
|
|
|
|
|
|
|
#define noteOffset 36
|
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
//#include <MIDI.h>
|
|
|
|
//#include <HID.h>
|
|
|
|
//MIDI_CREATE_DEFAULT_INSTANCE();
|
|
|
|
|
|
|
|
typedef struct OctaveStatus {
|
|
|
|
bool stat[12];
|
|
|
|
int nOct;
|
|
|
|
} octst;
|
2018-10-31 17:18:50 +01:00
|
|
|
|
|
|
|
int note[12] = {
|
2018-11-11 01:11:49 +01:00
|
|
|
C, Db, D, Eb, E, F, Gb, G, Ab, A, Bb, B }; // Note Pins above
|
2018-10-31 17:18:50 +01:00
|
|
|
int octave[4] = {
|
2018-11-11 01:11:49 +01:00
|
|
|
Oct1, Oct2, Oct3, Oct4 }; // Octave Pins above
|
2019-03-04 18:54:22 +01:00
|
|
|
int ledPins[12]{
|
|
|
|
19, 18, 17, 16, 15, 14, 2, 3, 4, 5, 6, 0 };
|
2018-11-11 01:11:49 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
int clock = 0;
|
|
|
|
octst buff;
|
2018-11-11 01:11:49 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
void setup() {
|
2018-10-31 17:18:50 +01:00
|
|
|
for (int cOctave = 0; cOctave < 4; cOctave++) {
|
|
|
|
pinMode(octave[cOctave], OUTPUT);
|
|
|
|
}
|
|
|
|
for (int cNote = 0; cNote < 12; cNote++) {
|
|
|
|
pinMode(note[cNote], INPUT);
|
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
for (int cLed = 0; cLed < 12; cLed++) {
|
|
|
|
pinMode(ledPins[cLed], OUTPUT);
|
|
|
|
}
|
|
|
|
// MIDI.begin(MIDI_CHANNEL_OFF);
|
2018-10-31 17:18:50 +01:00
|
|
|
Serial.begin(115200);
|
2019-03-04 18:54:22 +01:00
|
|
|
// nextBeat = millis() + (MINUTE / bpm);
|
|
|
|
for (int cLed = 0; cLed < 12; cLed++) {
|
|
|
|
digitalWrite(ledPins[cLed], HIGH);
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
for (int cLed = 0; cLed < 12; cLed++) {
|
|
|
|
digitalWrite(ledPins[cLed], LOW);
|
|
|
|
delay(100);
|
2018-11-11 02:00:08 +01:00
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
pinMode(50, OUTPUT);
|
2018-11-11 02:00:08 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
void loop() {
|
|
|
|
for (clock = 0; clock < 4; clock++) {
|
|
|
|
digitalWrite(octave[clock], HIGH);
|
|
|
|
buff = scan(clock);
|
|
|
|
digitalWrite(octave[clock], LOW);
|
|
|
|
//clean = clearOct(buff[0], buff[1], buff[2], buff[3], buff[4]);
|
|
|
|
debug(buff);
|
|
|
|
serialDebug(buff);
|
2018-11-11 02:00:08 +01:00
|
|
|
}
|
2018-10-31 17:21:02 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
bool debouncedRead(int pin) {
|
|
|
|
if (digitalRead(pin) == HIGH) {
|
|
|
|
if (digitalRead(pin) == HIGH) {
|
|
|
|
if (digitalRead(pin) == HIGH) {
|
|
|
|
if (digitalRead(pin) == HIGH) {
|
|
|
|
if (digitalRead(pin) == HIGH) {
|
|
|
|
return HIGH;
|
|
|
|
}
|
2018-10-31 17:44:56 +01:00
|
|
|
}
|
2018-10-31 17:21:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
return LOW;
|
2018-10-31 17:18:50 +01:00
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
octst scan(int nOct) {
|
|
|
|
int c;
|
|
|
|
octst output;
|
2018-10-31 17:18:50 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
output.nOct = nOct;
|
2018-11-11 01:11:49 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
for (c = 0; c < 12; c++) {
|
|
|
|
output.stat[c] = digitalRead(note[c]);
|
|
|
|
// delay(50);
|
2018-11-11 01:11:49 +01:00
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
return output;
|
2018-11-11 01:11:49 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
/*octst clearOct(octst o1, octst o2, octst o3, octst o4, octst o5) {
|
|
|
|
octst output;
|
2018-10-31 17:18:50 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
output.nOct = o1.nOct;
|
|
|
|
for (int c = 0; c < 12; +c++) {
|
|
|
|
if (o1.stat[c] && o2.stat[c] && o3.stat[c] && o4.stat[c] && o5.stat[c]) output.stat[c] = HIGH;
|
|
|
|
else output.stat[c] = LOW;
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}*/
|
2018-10-31 17:18:50 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
void debug(octst input) {
|
|
|
|
int c;
|
|
|
|
for (c = 0; c < 12; c++) {
|
|
|
|
digitalWrite(ledPins[c], input.stat[c]);
|
|
|
|
}
|
|
|
|
delay(5);
|
|
|
|
for (c = 0; c < 12; c++) {
|
|
|
|
digitalWrite(ledPins[c], LOW);
|
2018-10-31 17:18:50 +01:00
|
|
|
}
|
2018-11-11 01:11:49 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
void serialDebug(octst input) {
|
|
|
|
for (int c = 0; c < 12; c++) {
|
|
|
|
Serial.print(input.stat[c]);
|
2018-11-11 01:11:49 +01:00
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
Serial.println("");
|
2018-10-31 17:18:50 +01:00
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
|
|
|
|
/* debugLed(int c) {
|
|
|
|
switch (c) {
|
|
|
|
case 0: digitalWrite(2, HIGH);
|
|
|
|
break;
|
|
|
|
case 1: digitalWrite(3, HIGH);
|
|
|
|
break;
|
|
|
|
case 2: digitalWrite(4, HIGH);
|
|
|
|
break;
|
|
|
|
case 3: digitalWrite(2, LOW);
|
|
|
|
digitalWrite(3, LOW);
|
|
|
|
digitalWrite(4, LOW);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}*/
|