So I have a pretty simple project I'm looking to do. I want to hook up 10 foot switches, 8 to send midi control messages and the two others to increment up and decrement up. I'd also like to have an RGB led to identify which bank the controller is currently on. Before on the breadboard with a few two pin buttons and led the code worked perfectly, but since I moved on to the 3pdt I've encountered a recurring problem. Rather than going from low when you press in and back to high on release these switches go from high to low with each press.
The issue that has arisen is that when the switch is changed from high to low it cycles through the increments as if a standard momentary switch was being held down. But for my purposes I just want it to switch one and stop.
I'm not sure if that made sense but here's my code
#include <Control_Surface.h> // Include the Control Surface library
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
//comment this line if using a Common Cathode LED
#define COMMON_ANODE
// Instantiate a MIDI interface for use with the Hairless MIDI<->Serial bridge.
HairlessMIDI_Interface midi;
// Instantiate 3 Banks, with one address per bank.
// Banks can change the address of the buttons below.
// Having 3 banks means that each button has 3 possible addresses.
// 1 address per bank means that changing the bank increments the
// address (controller number) by 1.
Bank<4> bank(1);
// │ └───── number of addresses per bank
// └───────────── number of banks
// Instantiate a Bank selector to control which one of the three Banks is active.
// Pressing the push button will select the next bank, adding 1 to the address
// of the two buttons below. After 3 pushes, you're back at Bank 1.
IncrementDecrementSelector<4> selector = {
bank, // Bank to manage
{2, 3}, // push button pins (increment, decrement)
Wrap::Wrap, // Wrap around
};
// Instantiate two push buttons that send Control Change events when pressed
// or released.
Bankable::CCButton button1 = {
bank, // bank determines the address offset, relative to the base address
5, // push button pin
55, // base address (controller number)
};
Bankable::CCButton button2 = {
bank, // bank determines the address offset, relative to the base address
4, // push button pin
65, // base address (controller number)
};
Bankable::CCButton button3 = {
bank, // bank determines the address offset, relative to the base address
6, // push button pin
75, // base address (controller number)
};
Bankable::CCButton button4 = {
bank, // bank determines the address offset, relative to the base address
7, // push button pin
85, // base address (controller number)
};
Bankable::CCButton button5 = {
bank, // bank determines the address offset, relative to the base address
8, // push button pin
95, // base address (controller number)
};
Bankable::CCButton button6 = {
bank, // bank determines the address offset, relative to the base address
A5, // push button pin
105, // base address (controller number)
};
Bankable::CCButton button7 = {
bank, // bank determines the address offset, relative to the base address
A3, // push button pin
115, // base address (controller number)
};
Bankable::CCButton button8 = {
bank, // bank determines the address offset, relative to the base address
A1, // push button pin
45, // base address (controller number)
};
void setup() {
Control_Surface.begin(); // Initialize Control Surface
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
Control_Surface.loop(); // Update the Control Surface
if (bank.getSelection() == 0) setColor(14, 130, 150);
if (bank.getSelection() == 1) setColor(110, 0, 45);
if (bank.getSelection() == 2) setColor(200, 0, 0);
if (bank.getSelection() == 3) setColor(255, 120, 0);
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}