I have this program (Below), that runs fine the first time its uploaded and after hitting the reset button on the board, however once I unplug it and then re-plug it, no go. Iv'e tried it with an UNO and Mega.
Things I have tried include;
Multiple boards
Other power supplies, cords
Burning bootloaders
Testing both boards with "Blink" and "no delay blink" (Works fine with both under the exact same circumstances)
Le Code...
#include <MIDI.h>
// Initialize the MIDI library with default settings
MIDI_CREATE_DEFAULT_INSTANCE();
const int pins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
const int numPins = sizeof(pins) / sizeof(pins[0]);
const int debounceDelay = 50; // Debounce delay in milliseconds
// Array to store the last debounce time for each pin
unsigned long lastDebounceTime[numPins] = {0};
// Array to store the last stable state for each pin
bool lastPinState[numPins] = {HIGH};
// Array to store the current reading for each pin
bool pinReading[numPins] = {HIGH};
void setup() {
// Initialize MIDI communication
MIDI.begin(MIDI_CHANNEL_OMNI);
// Set up each pin as an input with an internal pull-up resistor
for (int i = 0; i < numPins; i++) {
pinMode(pins[i], INPUT_PULLUP);
}
}
void loop() {
for (int i = 0; i < numPins; i++) {
bool reading = digitalRead(pins[i]);
if (reading != lastPinState[i]) {
// Reset the debounce timer
lastDebounceTime[i] = millis();
}
if ((millis() - lastDebounceTime[i]) > debounceDelay) {
// If the reading has been stable for longer than the debounce delay
if (reading != pinReading[i]) {
pinReading[i] = reading;
// Determine the note number (arbitrary mapping for demonstration)
int note = i + 60; // Mapping pin to MIDI note (C4 = 60)
if (reading == LOW) {
// Send MIDI Note On message
MIDI.sendNoteOn(note, 127, 1);
} else {
// Send MIDI Note Off message
MIDI.sendNoteOff(note, 0, 1);
}
}
}
// Save the reading for the next loop iteration
lastPinState[i] = reading;
}
}
I'm trying to setup a MIDI pedalboard for a 1970's CONN theater organ that had an irreplaceable part go kaput on it.
Any help would be greatly appreciated!