WordPress won’t let me easily include code in comments, so I’ve posted it as a page. This code is used to control my Echoplex Digital Pro by sending specific midi CC messages, but these can easily be adapted to send other messages, PC, CC etc. Although it works, it’s nowhere near finished and there’s probably a much better way of doing the same thing. I’m also running out of arduino pins, so multiplexing will be required to add more buttons or leds. The learning curve never seems to flatten out ;(
#include <MIDI.h>
#include <Button.h>
// Constants
#define recLED 15
#define ovrLED 14
#define multLED 18
#define halfLED 16
#define revLED 17
#define BOUNCEDELAY1 100
#define BOUNCEDELAY2 20
Button RECbutton = Button(2,PULLUP);
Button OVRbutton = Button(3,PULLUP);
Button MULTbutton = Button(4,PULLUP);
Button UNDObutton = Button(5,PULLUP);
Button INSbutton = Button(6,PULLUP);
Button NEXTbutton = Button(7,PULLUP);
Button HALFbutton = Button(8,PULLUP);
Button REVbutton = Button(9,PULLUP);
// Variables:
int recLEDstatus = 0;
int ovrLEDstatus = 0;
int multLEDstatus = 0;
int halfLEDstatus = 0;
int revLEDstatus = 0;
void setup()
{
MIDI.begin(1);
//start serial with midi baudrate 31250 or 38400 for debugging
Serial.begin(31250);
Serial.flush();
// Setup Switches and activation LEDs
}
void loop()
{
// RECORD
if(RECbutton.isPressed())
{
MIDI.sendNoteOn(38,127,1); // record on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( RECbutton.isPressed() );
MIDI.sendNoteOn(38,0,1); // off
if (recLEDstatus == 0 )
{
analogWrite(recLED, 255);
recLEDstatus = 1;
delay(BOUNCEDELAY1);
}
else
{
analogWrite(recLED, 0);
recLEDstatus = 0;
}
}
// OVERDUB
if(OVRbutton.isPressed())
{
MIDI.sendNoteOn(39,127,1); // on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( OVRbutton.isPressed() );
MIDI.sendNoteOn(39,0,1); // off
if (ovrLEDstatus == 0 )
{
analogWrite(ovrLED, 255);
ovrLEDstatus = 1;
delay(BOUNCEDELAY1);
}
else
{
analogWrite(ovrLED, 0);
ovrLEDstatus = 0;
}
}
// MULTIPLY
if(MULTbutton.isPressed())
{
MIDI.sendNoteOn(40,127,1); // on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( MULTbutton.isPressed() );
MIDI.sendNoteOn(40,0,1); // off
if (multLEDstatus == 0 )
{
analogWrite(multLED, 255);
multLEDstatus = 1;
delay(BOUNCEDELAY1);
}
else
{
analogWrite(multLED, 0);
multLEDstatus = 0;
}
}
// UNDO
if(UNDObutton.isPressed())
{
MIDI.sendNoteOn(43,127,1); // on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( UNDObutton.isPressed() );
MIDI.sendNoteOn(43,0,1); // off
}
// INS
if(INSbutton.isPressed())
{
MIDI.sendNoteOn(38,127,1); // on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( INSbutton.isPressed() );
MIDI.sendNoteOn(38,0,1); // off
}
// NEXT
if(NEXTbutton.isPressed())
{
MIDI.sendNoteOn(44,127,1); // on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( NEXTbutton.isPressed() );
MIDI.sendNoteOn(44,0,1); // off
}
// HALF
if(HALFbutton.isPressed())
{
MIDI.sendNoteOn(48,127,1); // on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( HALFbutton.isPressed() );
MIDI.sendNoteOn(48,0,1); // off
if (halfLEDstatus == 0 )
{
analogWrite(halfLED, 255);
halfLEDstatus = 1;
delay(BOUNCEDELAY1);
}
else
{
analogWrite(halfLED, 0);
halfLEDstatus = 0;
}
}
// REV
if(REVbutton.isPressed())
{
MIDI.sendNoteOn(49,127,1); // record on
delay(BOUNCEDELAY2);
do {
delay(BOUNCEDELAY2);
}
while( REVbutton.isPressed() );
MIDI.sendNoteOn(49,0,1); // off
if (revLEDstatus == 0 )
{
analogWrite(revLED, 255);
revLEDstatus = 1;
delay(BOUNCEDELAY1);
}
else
{
analogWrite(revLED, 0);
revLEDstatus = 0;
}
}
}