Hi.
First off, I'm rubbish at maths and programming - C++ is a complete mystery to me.
I have built a FootPedal with 4x Momentary Switches and 4x LED's.
This is for controlling ONE channel of a Looper for 3 Musicians (A B C)
The Circuit is here (but it is a MICRO not a UNO board - JPG :
The Sketch, however, is beyond me.
I have studied numerous examples, but they are all very different (libraries, serial, etc.), so very hard to know what is best to do, and most of them won't even compile successfully.
I have started a Sketch with the basics (Pin definitions for Switches and LED's), but I am lost in the MIDI stuff, and getting the PINS>MIDI and MIDI>PINS is a mystery.
Could some kind soul take my basic Sketch and complete it please?
Here is the Sketch code with notes for the PIN numbers and MIDI Notes :
// START SKETCH
/*
Concept by William Hitchings, 09-2023
SKETCH to run a MIDI FOOTPEDAL comprising of :
4x Momentary Switches (Pins 5-6-7-8) to trigger specified MIDI notes.
4x LEDs (Pins 9-10-11-12) to Flash when specified MIDI notes received.
The Foot Pedal is to operate a 3-Person ( A B C ) Looping Machine built in MAX-MSP.
This Sketch is to operate one of the 3 Controllers, each with their own MIDI Switch numbers. So there will be 2 other controllers with relevant MIDI notes for Players B and C.
Hence why some parts are copied and greyed out, for the other controllers.
The LED's are for Tempo Counters, so the MIDI is the same for all controllers.
I understand the 'concept' of arrays, but since I only have 4 switches and LED's it seemed easier not to use them.
This runs on an ARDUINO MICRO board.
MIDI SWITCH NOTE NUMBERS
========================
37 = REC A
39 = DEL A
42 = REC B
44 = DEL B
46 = RESET
49 = REC C
51 = DEL C
54 = OVERDUB A
56 = OVERDUB B
58 = OVERDUB C
MIDI NOTES TO FLASHERS
======================
40 = LED-1
41 = LED-2
47 = LED-3
48 = LED-4
PIN NUMBERS
===========
SW1 = 5
SW2 = 6
SW3 = 7
SW4 = 8
LED1 = 9
LED2 = 10
LED3 = 11
LED4 = 12
*/
#include <USB-MIDI.h> // ?? Correct Library ?
USBMIDI_CREATE_DEFAULT_INSTANCE();
unsigned long t0 = millis();
unsigned long tClock = millis();
using namespace MIDI_NAMESPACE;
midiEventPacket_t read(void);
void sendMIDI(midiEventPacket_t event);
void flush(void);
// const uint8_t button1 = 2;
/*
#define SW1Pin 5 // SWITCH PINS
#define SW2Pin 6
#define SW3Pin 7
#define SW4Pin 8
#define LED1Pin 9 // LED PINS
#define LED2Pin 10
#define LED3Pin 11
#define LED4Pin 12
*/
int SW1Pin = 5; // SWITCH PINS
int SW2Pin = 6;
int SW3Pin = 7;
int SW4Pin = 8;
int LED1Pin = 9; // LED PINS
int LED2Pin = 10;
int LED3Pin = 11;
int LED4Pin = 12;
int val = 0;
void digitalWrite(uint8_t pin, uint8_t val);
void digitalRead(uint8_t pin, uint8_t val);
void setup(){
{
// Set MIDI baud rate:
Serial.begin(31250);
MIDI.begin(1); // Launch MIDI and listen to channel 1
}
{// LED FLASHERS
pinMode(LED1Pin, OUTPUT);
pinMode(LED2Pin, OUTPUT);
pinMode(LED3Pin, OUTPUT);
pinMode(LED4Pin, OUTPUT);
}
{ // MIDI SWITCHES
pinMode(SW1Pin, INPUT);
pinMode(SW2Pin, INPUT);
pinMode(SW3Pin, INPUT);
pinMode(SW4Pin, INPUT);
}
}
void loop() {
MIDI.read();
{
// read the SWITCH input pin
{
val = digitalRead(SW1Pin);
val = digitalRead(SW2Pin);
val = digitalRead(SW3Pin);
val = digitalRead(SW4Pin);
}
// write to LED output pin
digitalWrite(LED1Pin, HIGH);
digitalWrite(LED2Pin, HIGH);
digitalWrite(LED3Pin, HIGH);
digitalWrite(LED4Pin, HIGH);
// Received a MIDI message
{
{ digitalWrite(LED1Pin, HIGH); // LED 1 ON
delay(300);
digitalWrite(LED1Pin, LOW);
}
{ digitalWrite(LED2Pin, HIGH); // LED 2 ON
delay(300);
digitalWrite(LED2Pin, LOW);
}
{digitalWrite(LED3Pin, HIGH); // LED 3 ON
delay(300);
digitalWrite(LED3Pin, LOW);}
{ digitalWrite(LED4Pin, HIGH); // LED 4 ON
delay(300);
digitalWrite(LED4Pin, LOW);}
}
}
{
MIDI.sendNoteOn(37, 127, 1); // Send Note 37 (REC-A), velo 127 on channel 1)
delay(100); // Wait for 100ms
MIDI.sendNoteOff(42, 0, 1); // Stop the note
MIDI.sendNoteOn(39, 127, 1); // Send Note 39 (DEL-A), velo 127 on channel 1)
delay(100); // Wait for a second
MIDI.sendNoteOff(42, 0, 1); // Stop the note
MIDI.sendNoteOn(54, 127, 1); // Send Note 54 (DUB-A), velo 127 on channel 1)
delay(100); // Wait for 100ms
MIDI.sendNoteOff(42, 0, 1); // Stop the note
MIDI.sendNoteOn(46, 127, 1); // Send Note 46 (RESET), velo 127 on channel 1)
delay(100); // Wait for 100ms
MIDI.sendNoteOff(42, 0, 1); // Stop the note
}
void flush(void);
}
// END SKETCH
If someone could help, I'd be eternally grateful!
I'm not sure if the Libraries I'm using are appropriate or not, since the code seems very dependent on the correct Libraries to work.
Thanks again in advance!
WillH