The Code:
int buttonPins[5] = {29, 30, 31, 32, 33};
int totalButtons = 5;
int ledPins[4] = {7, 8, 9, 10};
int total = 4;
int channelLEDs[3] = {18, 17, 16};
int totalChannels = 3;
bool lastButtonState[4] = {LOW, LOW, LOW, LOW};
bool buttonState[4] = {LOW, LOW, LOW, LOW};
bool lastButtonState2 = LOW;
bool buttonState2 = LOW;
int currentStep2 = 0;
bool switchedOn[3][4] = {
{false, true, false, false},
{false, true, true, true},
{true, false, true, false}
};
unsigned long lastStepTime = 0;
int currentStep = 0;
int tempo = 0;
int channelDisplayed = 0;
int midiNotes[3] = {60, 61, 62};
void setup() {
for(int i = 0; i < total; i++){
pinMode(ledPins[i], OUTPUT);
}
for(int i = 0; i < totalButtons; i++){
pinMode(buttonPins[i], INPUT);
}
for(int i = 0; i < totalChannels; i++){
pinMode(channelLEDs[i], OUTPUT);
}
}
void loop() {
checkChannelButton();
updateChannelLeds();
checkButton();
updateLeds();
tempo = analogRead(A15);
stepForwards();
}
void stepForwards(){
if(millis() >= tempo + lastStepTime){
lastStepTime = millis();
for(int i = 0; i < totalChannels; i++){
usbMIDI.sendNoteOff(midiNotes[i], 127, 1);
if(switchedOn[i][currentStep] == HIGH){
usbMIDI.sendNoteOn(midiNotes[i], 127, 1);
}
}
currentStep++;
}
if(currentStep == total){
currentStep = 0;
}
}
void checkButton(){
for(int i = 0; i < total; i++){
lastButtonState[i] = buttonState[i];
buttonState[i] = digitalRead(buttonPins[i]);
if(lastButtonState[i] == LOW && buttonState[i] == HIGH){
switchedOn[channelDisplayed][i] = !switchedOn[channelDisplayed][i];
delay(5);
}
else if(lastButtonState == HIGH && buttonState == LOW ){
delay(5);
}
}
}
void checkChannelButton(){
lastButtonState2 = buttonState2;
buttonState2 = digitalRead(buttonPins[4]);
if(lastButtonState2 == LOW && buttonState2 == HIGH){
channelDisplayed++;
delay(5);
}
else if(lastButtonState2 == HIGH && buttonState2 == LOW ){
delay(5);
}
if(channelDisplayed >= totalChannels){
channelDisplayed = 0;
}
}
void updateChannelLeds(){
for(int i = 0; i < totalChannels; i++){
if(i == channelDisplayed){
digitalWrite(channelLEDs[i], HIGH);
}
else{
digitalWrite(channelLEDs[i], LOW);
}
}
}
void updateLeds(){
for(int i = 0; i < total; i++){
if(switchedOn[channelDisplayed][i] == true or i == currentStep){
digitalWrite(ledPins[i], HIGH);
}
else{
digitalWrite(ledPins[i], LOW);
}
}
}
For my final project, I’d like to combine the multi-channel drum sequencer with visuals from Processing. I would like to have visuals that reflected the sound coming from the drum sequencer. I’m not sure how ambitious this project idea is yet, but right now I also think I would add more channels as well as steps in the sequence. I might try to add more of the ideas listed in the final project post, but the main idea is to combine visuals from Processing with the multi-channel drum sequencer.