how to add 2 more pots to this code

Thread Starter

seayaker

Joined Jan 27, 2009
54
This is for a midi controller that has 3 buttons and 1 pot. I simply want to add 2 more pots and keep the rest of the code intact. I want to add more later but to learn and understand, if someone could just show me how I could add 2 more pots. I'd be grateful. I have 3 pots connected to A0, A1 and A2. I just need to adjust the code.


#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 1;

Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);
Bounce button2 = Bounce(2, 5);

byte current_value_1;
byte previous_value_1;

void setup() {
analogReadResolution(7); // set the analog read resolution to 7 bits (a range of 0 - 127)
analogReadAveraging(32); // average the analog value by averaging 16 readings
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
}

void loop() {
button0.update();
button1.update();
button2.update();
current_value_1 = analogRead(0);
if (button0.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4
}
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOn(62, 99, channel); // 61 = C#4
}
if (button0.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel); // 60 = C4
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(62, 0, channel); // 61 = C#4
}
if(current_value_1 != previous_value_1) {
previous_value_1 = current_value_1;
usbMIDI.sendControlChange(1, current_value_1, 1); // send continuous controller message
}


}
 

bug13

Joined Feb 13, 2012
1,705
just add these accordlingly

Code:
current_value_2 = analogRead(1);
current_value_3 = analogRead(2);
 
Top