USB MIDI Lab:
My Code:
int redLED = 10;
int yellowLED = 24;
int blueLED = 26;
int greenLED = 28;
int buttonPin1 = 36;
int buttonPin2 = 35;
int buttonPin3 = 33;
int buttonPin4 = 32;
int toggle = 29;
int potValue = 0;
void setup() {
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(toggle, INPUT);
}
void loop() {
toggleMode();
}
void keyboardMode() {
checkButton(buttonPin1, redLED, 60);
checkButton(buttonPin2, yellowLED, 64);
checkButton(buttonPin3, blueLED, 67);
checkButton(buttonPin4, greenLED, 71);
}
void arpeggiatorMode() {
if (digitalRead(buttonPin1) == HIGH) {
arpeggio(60);
}
if (digitalRead(buttonPin2) == HIGH) {
arpeggio(64);
}
if (digitalRead(buttonPin3) == HIGH) {
arpeggio(67);
}
if (digitalRead(buttonPin4) == HIGH) {
arpeggio(71);
}
}
void toggleMode() {
if (digitalRead(toggle) == LOW) {
arpeggiatorMode();
}
if (digitalRead(toggle) == HIGH) {
keyboardMode();
}
}
void arpeggio(int note) {
potValue = analogRead(A19); //variable for the analog input pin of potentiometer
usbMIDI.sendNoteOn(note, 127, 1);
digitalWrite(redLED, HIGH);
delay(potValue);
usbMIDI.sendNoteOff(note, 0, 1);
digitalWrite(redLED, LOW);
usbMIDI.sendNoteOn(note + 4, 127, 1);
digitalWrite(yellowLED, HIGH);
delay(potValue);
usbMIDI.sendNoteOff(note + 4, 0, 1);
digitalWrite(yellowLED, LOW);
usbMIDI.sendNoteOn(note + 7, 127, 1);
digitalWrite(blueLED, HIGH);
delay(potValue);
usbMIDI.sendNoteOff(note + 7, 0, 1);
digitalWrite(blueLED, LOW);
usbMIDI.sendNoteOn(note + 11, 127, 1);
digitalWrite(greenLED, HIGH);
delay(potValue);
usbMIDI.sendNoteOff(note + 11, 0, 1);
digitalWrite(greenLED, LOW);
}
void checkButton(int buttonPin, int ledPin, int note) {
if (digitalRead(buttonPin) == HIGH) {
digitalWrite(ledPin, HIGH);
usbMIDI.sendNoteOn(note, 127, 1);
delay(500);
digitalWrite(ledPin, LOW);
usbMIDI.sendNoteOff(note, 0, 1);
}
}