#include <MIDIUSB.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
// Simple MIDI output of program message through USB
// By Grumpy_Mike August 2019
// to add more then simply add more pins tothe list
byte ledPin[] = {A3,A2,A1,A9,A8,A0}; // list of led pins
byte buttonPin[] = {10,6,1,5,7,0}; // list of buttons pins
byte buttonState[] = {0,0,0,0,0,0}; // start off with off
byte lastButtonState[] = {0,0,0,0,0,0}; // start off with off
byte programChanges[] = {0,1,2,3,4,5}; // list of program change messages to send
byte controlChanges [] = {(0, 12, 127), (0, 13, 127)};
byte channel = 0; // for musicians this is channel 1
// this constant won't change:
const int Up_buttonPin = 0; // the pin that the pushbutton is attached to
const int Down_buttonPin = 7;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int up_buttonState = 0; // current state of the up button
int up_lastButtonState = 0; // previous state of the up button
int down_buttonState = 0; // current state of the up button
int down_lastButtonState = 0; // previous state of the up button
bool bPress = false;
char *myStrings[] = {" Fender", " Plexy", " Mesa", " 5150", " Dumble",
" Soldano ", " Triple Rec " };
void setup() {
for(int i =0;i< sizeof(buttonPin); i++){ // initialise input pins
pinMode(buttonPin[i], INPUT_PULLUP); // wire all buttons between input and ground
pinMode(ledPin[i], OUTPUT);
}
{
Serial.begin(9600);
pinMode( Up_buttonPin , INPUT_PULLUP);
pinMode( Down_buttonPin , INPUT_PULLUP);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Banks:");
lcd.setCursor(1,1);
lcd.print(buttonPushCounter);
}
}
void loop() {
for(int i =0;i< sizeof(buttonPin); i++){ // look at all pins
buttonState[i] = digitalRead(buttonPin[i]);
if(buttonState[i] == LOW && lastButtonState[i] == HIGH) { // remember how you wired your buttons LOW = pressed
ledOffAll();
digitalWrite(ledPin[i],HIGH);
programChange(channel, programChanges[i]); // send the program change message
MidiUSB.flush();
delay(50);
}
lastButtonState[i] = buttonState[i];
}
}
void ledOffAll() {
for(int i = 0 ; i< sizeof(ledPin); i++){
digitalWrite(ledPin[i], LOW);
}
}
void programChange(byte channel, byte patch) {
midiEventPacket_t event = {0x0C, 0xC0 | channel, patch};
MidiUSB.sendMIDI(event);}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
MidiUSB.flush();
if( Up_buttonPin == HIGH ){
controlChange(0, 12, 127);
} else {
programChange(0, 120);
MidiUSB.flush();
}
{
checkUp();
checkDown();
}
if( bPress){
bPress = false;
lcd.setCursor(2,1);
lcd.print(" ");
lcd.setCursor(221,1);
lcd.print(buttonPushCounter[myStrings]);
}
}
void checkUp()
{
up_buttonState = digitalRead(Up_buttonPin);
// compare the buttonState to its previous state
if (up_buttonState != up_lastButtonState) {
// if the state has changed, increment the counter
if (up_buttonState == LOW) {
bPress = true;
buttonPushCounter++; // if the current state is HIGH then the button went from off to on:
}
// Delay a little bit to avoid bouncing
//delay(5);
}
// save the current state as the last state, for next time through the loop
up_lastButtonState = up_buttonState;
}
void checkDown()
{
down_buttonState = digitalRead(Down_buttonPin);
// compare the buttonState to its previous state
if (down_buttonState != down_lastButtonState) {
// if the state has changed, increment the counter
if (down_buttonState == LOW) {
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter--;
}
// Delay a little bit to avoid bouncing
//delay(5);
}
// save the current state as the last state, for next time through the loop
down_lastButtonState = down_buttonState;
}
Sorry. This is the disadvantage of starting from scratch. I really am lost and clueless. don't have any idea what to do, that is why..
I don't see a CC in midiOx, only PC.