#include <Bounce.h>
//**********CONSTANTS**********
const int BOUNCE_TIME = 25; // fine tune if the buttons need more/less time
const int LEDPIN = 13; // Upper BANK indicator LED
const int DIGITAL_PINS = 5; // size of the PINS array (no longer includes toggle button!)
const int PINS[DIGITAL_PINS] = {0,1,2,3,4}; // set pin numbers of swtiches
const int channel = 1;
const int ONvalue = 127; // arbitrary 'on' value for D2 of CC message
const int OFFvalue = 0; // arbitrary 'off' value for D2 of CC message
const int resetThreshold = 2000; /// mS hold to change bank
const byte CC[][DIGITAL_PINS] = {
[COLOR="#FF0000"] {60,61,62,63,64},
{65,66,67,68,69},
{70,71,72,73,74},
{75,76,77,78,79},
{80,81,82,83,84},
{85,86,87,88,89}[/COLOR]
}; // this is the banks by switches matrix of CC values for the bank system
//**********VARIABLES/LIBRARY OBJECTS**********
int bank = 0; // this is the bank variable to be toggled
boolean CCstate[DIGITAL_PINS]; // array of current CC on/off toggle state
boolean timerOn; // timer toggle memory tracks whether a new fallingEdge was heard since the last rising; used in bank switching
Bounce btn[] = {
Bounce(PINS[0], BOUNCE_TIME),
Bounce(PINS[1], BOUNCE_TIME),
Bounce(PINS[2], BOUNCE_TIME),
Bounce(PINS[3], BOUNCE_TIME),
Bounce(PINS[4], BOUNCE_TIME),
};
elapsedMillis toggleReset; // mS clock counter to reset on contact/risgingEdge()
//**********SETUP**********
void setup() {
//Serial.begin(9600);
for (int i = 0;i<DIGITAL_PINS;i++){
pinMode(PINS[i], INPUT_PULLUP);
}
pinMode(LEDPIN, OUTPUT);
}
//**********LOOP**********
void loop() {
for (int i = 0;i<DIGITAL_PINS;i++){ // loop through each object in the BOUNCE arrray for the note switches (no longer includes TOGGLE)
btn[i].update();
if (btn[i].fallingEdge()) {
timerOn = true ;
toggleReset = 0;
}
if (btn[i].risingEdge()) {
if(toggleReset<resetThreshold){
if (CCstate[i]){
usbMIDI.sendControlChange(CC[bank][i], ONvalue, channel);
}else{
usbMIDI.sendControlChange(CC[bank][i], OFFvalue, channel);
}
CCstate[i] = !CCstate[i] ; //toggle state memory
timerOn = false ; //turn off timer (resets each cycle)
}
}
if (timerOn && (toggleReset>resetThreshold)){
toggleReset = 0;
bank =[COLOR="#FF0000"] i;[/COLOR]
[COLOR="#FF0000"] //digitalWrite(LEDPIN, bank); // turn off for now...[/COLOR]
}
}
}