int blueLed = 7; // create variables for each of the components on the breadboard
int greenLed = 8;
int whiteLed = 9;
int yellowLed = 10;
int tempoPin = A13;
int potPin1 = A14;
int potPin2 = A15;
int potPin3 = A16;
int potPin4 = A17;
int octaveSwitch = 28;
int powerSwitch = 27;
int tempoVal = 0; //map variables
int lastTempoVal = 0;
int potVal1 = 0;
int lastPotVal1 = 0;
int potVal2 = 0;
int lastPotVal2 = 0;
int potVal3 = 0;
int lastPotVal3 = 0;
int potVal4 = 0;
int lastPotVal4 = 0;
int octave = 12; //octave switch variable
void setup() {
pinMode(blueLed, OUTPUT); //pinMode for LEDs and switches
pinMode(greenLed, OUTPUT);
pinMode(whiteLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(octaveSwitch, INPUT);
pinMode(powerSwitch, INPUT);
}
void loop() {
stepSequencer(); //stepSequencer and checkOctave
checkOctave();
}
void stepSequencer() { //stepSequencer function
if (digitalRead(powerSwitch) == HIGH) { //powerSwitch must be turned on
lastTempoVal = tempoVal; // tempo map
tempoVal = map(analogRead(tempoPin), 0, 1023, 100, 1000);
lastPotVal1 = potVal1; //first pitch
potVal1 = map(analogRead(potPin1), 0, 1023, 60, 72); //first pitch map
digitalWrite(blueLed, HIGH); // the first LED and pitch turns on, the rest are off
digitalWrite(greenLed, LOW);
digitalWrite(whiteLed, LOW);
digitalWrite(yellowLed, LOW);
usbMIDI.sendNoteOn(potVal1 - octave, 127, 1);
delay(tempoVal); // the LED and pitch remains like this for a value determined by the pot
usbMIDI.sendNoteOff(potVal1 - octave, 0, 1); //note off
lastPotVal2 = potVal2; //second pitch
potVal2 = map(analogRead(potPin2), 0, 1023, 60, 72); //second pitch map
digitalWrite(blueLed, LOW); // the second LED and pitch turns on, the rest are off
digitalWrite(greenLed, HIGH);
digitalWrite(whiteLed, LOW);
digitalWrite(yellowLed, LOW);
usbMIDI.sendNoteOn(potVal2 - octave, 127, 1);
delay(tempoVal); // the LED and pitch remains like this for a value determined by the pot
usbMIDI.sendNoteOff(potVal2 - octave, 0, 1); //note off
lastPotVal3 = potVal3; // third pitch
potVal3 = map(analogRead(potPin3), 0, 1023, 60, 72); //third pitch map
digitalWrite(blueLed, LOW); // the third LED and pitch turns on, the rest are off
digitalWrite(greenLed, LOW);
digitalWrite(whiteLed, HIGH);
digitalWrite(yellowLed, LOW);
usbMIDI.sendNoteOn(potVal3 - octave, 127, 1);
delay(tempoVal); // the LED and pitch remains like this for a value determined by the pot
usbMIDI.sendNoteOff(potVal3 - octave, 0, 1); //note off
lastPotVal4 = potVal4; // fourth pitch
potVal4 = map(analogRead(potPin4), 0, 1023, 60, 72); //fourth pitch map
digitalWrite(blueLed, LOW); // the fourth LED and pitch turns on, the rest are off
digitalWrite(greenLed, LOW);
digitalWrite(whiteLed, LOW);
digitalWrite(yellowLed, HIGH);
usbMIDI.sendNoteOn(potVal4 - octave, 127, 1);
delay(tempoVal); // the LED and pitch remains like this for a value determined by the pot
usbMIDI.sendNoteOff(potVal4 - octave, 0, 1); //note off
digitalWrite(blueLed, LOW); //LEDs turn off
digitalWrite(greenLed, LOW);
digitalWrite(whiteLed, LOW);
digitalWrite(yellowLed, LOW);
}
}
void checkOctave() { //checkOctave function
if (digitalRead(octaveSwitch) == LOW) { //if switch is off, octave is 0, won't add anything to the pitches
octave = 0;
}
if (digitalRead(octaveSwitch) == HIGH) { // if switch is on, octave is 12, will subtract an octave from the pitches
octave = 12;
}
}