slightly frustrated lol
/* Arduino USB MIDI demo */
#define NOTE_OFF 0x80
#define NOTE_ON 0x90
/* The format of the message to send via serial */
typedef struct {
uint8_t command;
uint8_t channel;
uint8_t data2;
uint8_t data3;
}
t_midiMsg;
int ledPin = 11; //choose the pin for the LED - needs to be (3,5,6,9,10, or 11)
int buttonPin = 2; //choose the input pin for a pushbutton
int MAX_PINS = sizeof(buttonPin)/2-1;
int potPin = 0; //choose the input pin for a potentometer
int buttonVal = 0; //variable for reading the button status
int buttonState = 0; //variable to hold the buttons current state
int bounceCheck = 0; //variable for debouncing
int potVal = 0; //variable for reading potentiometer value
int mappedPotVal = 0; //variable for holding remapped pot value
int prevPotVal = 0; //variable for storing our prev pot value
int THRESHOLD = 2; //threshold amount
int channel = 1;
void setup()
{
pinMode(ledPin, OUTPUT); //declare LED as output
pinMode(buttonPin, INPUT); //declare pushbutton as input
Serial.begin(115200);
delay(200);
}
/* List of notes to play, zero terminated */
void loop()
{
buttonVal = digitalRead(buttonPin); //read input value from button
delay(10); //wait 10ms
bounceCheck = digitalRead(buttonPin); //check again
if(buttonVal == bounceCheck){ //if val is the same then not a bounce
if (buttonVal == HIGH && buttonState == 1) { //check if the input is HIGH
digitalWrite(ledPin, LOW); //turn LED OFF
sendmidi(NOTE_OFF, 60, 127); //Note ON (CH 1), middle C, zero velocity turns note off
buttonState = 0;
}
if(buttonVal == LOW && buttonState == 0){
digitalWrite(ledPin, HIGH); //turn LED ON
sendmidi(NOTE_ON, 60, 127); //Note ON (CH 1), middle C, velocity 127
buttonState = 1;
}
}
potVal = analogRead(potPin); //read input from potentiometer
mappedPotVal = map(potVal, 0, 1023, 0, 127); //map value to 0-127
if(abs(mappedPotVal - prevPotVal) >= THRESHOLD){
sendmidi(0xB0, 1, mappedPotVal); //Control Change (Ch 1), Controller 7 - default control for volume.
digitalWrite(ledPin, HIGH);
prevPotVal = mappedPotVal;
}
else{
digitalWrite(ledPin, LOW);
}
}
void sendmidi(int command,int data2, int data3){
t_midiMsg msg;
int ind;
/* Send the notes */
msg.command = command; //noteon
msg.channel = channel;
msg.data2 = data2; //note
msg.data3 = data3; /* Velocity */
Serial.write((uint8_t *)&msg, sizeof(msg));
}
this is the code im using ti read the state of 1 pushbutton with debounce and state change and one pot and they out put midi messages i would like to know if some one could show me how to phrase this code so that i may have multiple buttons and multible pots? my set up us 12 buttons and 4 pots thank you so much