heres the whole thing....
/*
Arduino Mega MIDI foot controller:
-LCD printout
-4 pedals
-13 Instant Access Programmable buttons
- 2 bank up down buttons
R1.2.0 as of Dec.8th 2010:
there is TX contant output...
after one read through the program, it get's stuck on midi send of the pedal..
R1.2.1 12-8-2010
fixed bank down button, still problem with midi send and bank up, resent works nicely
*/
#define S1 51
#define S2 47
#define S3 43
#define S4 39
#define S5 35
#define S6 34
#define S7 30
#define S8 26
#define S9 31
#define Bank_up 27
#define S10 3
#define S11 46
#define S12 50
#define S13 42
#define Bank_down 38
#define Pot_a A0
#define Pot_b A1
#define Pot_c A2
#define Pot_d A3
#define LED1 49
#define LED2 45
#define LED3 41
#define LED4 37
#define LED5 33
#define LED6 32
#define LED7 28
#define LED8 24
#define LED9 29
#define LED10 2
#define LED11 44
#define LED12 48
#define LED13 40
#include <MIDI.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 10, 4, 5, 6, 7);
int SWITCHES[14] = {
0,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13};
int SWITCHSTATES[14] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int SWITCHVAR[14] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int SWITCHVAR_OLD[14] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int BANKS[3]={
0,Bank_up,Bank_down};
int BANKSTATE[3]={
0,0,0};
int LEDS[14] = {
0, LED1,LED2,LED3,LED4,LED5,LED6,LED7,LED8,LED9,LED10,LED11,LED12,LED13};
int LEDSTATE[14] = {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int PEDALS[5] = {
0,A0,A1,A2,A3};
int PEDALSTATE[5] = {
0,0,0,0,0};
int PEDALSTATE_OLD[5] = {
0,0,0,0,0};
void setup() {
for(int d=1;d<14;d++){
pinMode(LEDS[d],OUTPUT);
pinMode(SWITCHES[d], INPUT);
digitalWrite(SWITCHES[d], HIGH);
SWITCHSTATES[d] = HIGH;
}
for(int d=1;d<3;d++){
pinMode(BANKS[d], INPUT);
digitalWrite(BANKS[d], HIGH);
BANKSTATE[d] = HIGH;
}
pinMode(36, OUTPUT);
pinMode(25, OUTPUT);
MIDI.begin();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Arduino GCP");
lcd.setCursor(0,1);
lcd.print("By EN R.1.2.0");
}
int Bank = 0;
int Bank_old = 0;
void loop() { //MAIN LOOP
/*
for(int a=1;a<3;a++){
if(digitalRead(BANKS[a]==LOW) && (BANKSTATE[a] ==HIGH)){
delay(75);
if(BANKS[a] == Bank_up){
if (Bank ==127) {Bank = 0;}
else {Bank ++;}
}
else if(BANKS[a] == Bank_down){
if (Bank ==0) {Bank = 127;}
else {Bank--;};
}
else {break;}
}
digitalWrite(BANKS[a], HIGH);
}
*/
if((digitalRead(Bank_down)==LOW) &&(BANKSTATE[2]==HIGH)){// bank down works
digitalWrite(36,HIGH);
delay(175);
digitalWrite(36,LOW);
switch (Bank){
case 0:
Bank = 127;
default:
Bank--; // reads bank down button
}
digitalWrite(Bank_down, HIGH);
}
if((digitalRead(Bank_up)==LOW) &&(BANKSTATE[1]==HIGH)){ //bank works very poorly
digitalWrite(36, HIGH);
delay(100);
digitalWrite(36,LOW);
// switch (Bank){
//case 127:
// Bank = 0;
// default:
Bank++; // reads bank up button
// }
digitalWrite(Bank_up, HIGH);
}
if(Bank != Bank_old){
SWITCHRESET(); // if pressed reset switches & LED's - works
LCDBANKCHANGE(Bank);
Bank_old = Bank;
}
//check if change in pedals
for(int Ptest=1;Ptest<5;Ptest++){
PEDALSTATE[Ptest] = analogRead(PEDALS[Ptest]);
if(PEDALSTATE[Ptest] != PEDALSTATE_OLD[Ptest]){
MIDIPEDALSEND(PEDALSTATE[Ptest],Bank,Ptest);
}
}
AISWITCHPRESS(Bank); //after bank check and pedal check check 13 AI switches seems to work with LEDS
}
void SWITCHRESET(){
for(int a=1;a<14;a++){
LEDSTATE[a] = -1;
digitalWrite(SWITCHES[a], HIGH);
digitalWrite(LEDS[a], LOW);
SWITCHSTATES[a] = HIGH;
}
}
void LCDBANKCHANGE(int bank){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Bank: ");
lcd.print(bank);
}
void MIDIPEDALSEND(int val, int bank, int Pedal){
int CC_Designation[4][128]={ //which CC designation does each pedal have? 4 pedals x 128 CC's
{
0,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14 }
,
{
0,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14 }
,
{
0,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14 }
,
{
0,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14 }
};
int CH_designation[4][128]={
{
0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 }
,
{
0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 }
,
{
0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 }
,
{
0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 }
,
};
// MIDI.send(CC,CC_Designation[Pedal][Bank],val,CH_designation[Pedal][Bank]); //with this commented out, no TX problem, but no Bank response
}
void AISWITCHPRESS(int Bank){
for(int a=1;a<16;a++){
if ((digitalRead(SWITCHES[a])==LOW)&& (SWITCHSTATES[a] == HIGH)){
LEDSTATE[a]=LEDSTATE[a]*(-1);
delay(175); //RELEASE TIME - varies depending on program size. allows for release to only trigger one change.
//Break at this point, need to send to MASTER AI BANK CHANGE program
//where Switch #, LEDSTATE, SWITCH assignment is taken into account and then sorted out what to do
MASTERSWITCHER(a, Bank);
}
if(SWITCHVAR_OLD[a] != SWITCHVAR[a]){
//MIDISEND(e,SWITCHVAR[e]);
SWITCHVAR_OLD[a]=SWITCHVAR[a];
}
}
for(int f=1;f<16;f++){ //this part resets the switches to high
digitalWrite(SWITCHES[f], HIGH);
SWITCHSTATES[f] = HIGH;
}
}
void MASTERSWITCHER(int Switch, int Bank) { //this program needs to read the switch & bank value, and spit out correct
// midi message and LED display.
if (LEDSTATE[Switch] <0){
SWITCHVAR[Switch] =0;
digitalWrite(LEDS[Switch],LOW); //writes to LED, need to change for MAIN BANK/AI Program
}
else {
SWITCHVAR[Switch] = 127;
digitalWrite(LEDS[Switch], HIGH);
}
}