I did it.
int led1Pin = 7; int led2Pin = 8; int led3Pin = 9; int led4Pin = 10; int button1Pin = 33; int button2Pin = 34; int button3Pin = 35; int button4Pin = 36; int switchPin = 37; int switch2Pin = 38; int noteSpeed = 200; void setup() { Serial.begin(9600); pinMode(led1Pin, OUTPUT); pinMode(led2Pin, OUTPUT); pinMode(led3Pin, OUTPUT); pinMode(led4Pin, OUTPUT); pinMode(button1Pin, INPUT); pinMode(button2Pin, INPUT); pinMode(button3Pin, INPUT); pinMode(button4Pin, INPUT); pinMode(switchPin, INPUT); pinMode(switch2Pin, INPUT); } void loop() { if(digitalRead(switchPin) == HIGH) { arpeggiatorMode(); } else { keyboardMode(); } } void keyboardMode() { checkButton(button1Pin, led1Pin, 60); checkButton(button2Pin, led2Pin, 62); checkButton(button3Pin, led3Pin, 63); checkButton(button4Pin, led4Pin, 65); } void checkButton(int buttonPin, int ledPin, int note) { if(digitalRead(switch2Pin) == HIGH) note += 12; if(digitalRead(buttonPin) == HIGH) { digitalWrite(ledPin, HIGH); usbMIDI.sendNoteOn(note, 127, 1); delay(500); digitalWrite(ledPin, LOW); usbMIDI.sendNoteOff(note, 0, 1); } } void arpeggiatorMode() { noteSpeed = constrain(analogRead(A13), 100, 1023); checkButtonArp(button1Pin, 60); checkButtonArp(button2Pin, 62); checkButtonArp(button3Pin, 63); checkButtonArp(button4Pin, 65); } void checkButtonArp(int buttonPin, int note) { if(digitalRead(buttonPin) == HIGH) { arpeggio(note); } } void arpeggio(int note) { if(digitalRead(switch2Pin) == HIGH) note += 12; digitalWrite(led1Pin, HIGH); usbMIDI.sendNoteOn(note, 127, 1); delay(noteSpeed); digitalWrite(led1Pin, LOW); usbMIDI.sendNoteOff(note, 0, 1); digitalWrite(led2Pin, HIGH); usbMIDI.sendNoteOn((note + 4), 127, 1); delay(noteSpeed); digitalWrite(led2Pin, LOW); usbMIDI.sendNoteOff((note + 4), 0, 1); digitalWrite(led3Pin, HIGH); usbMIDI.sendNoteOn((note + 7), 127, 1); delay(noteSpeed); digitalWrite(led3Pin, LOW); usbMIDI.sendNoteOff((note + 7), 0, 1); digitalWrite(led4Pin, HIGH); usbMIDI.sendNoteOn((note + 11), 127, 1); delay(noteSpeed); digitalWrite(led4Pin, LOW); usbMIDI.sendNoteOff((note + 11), 0, 1); }
0 Comments