Hi arduino-Istas,
I am on my first code programming roller coaster ride, trying to midify my organ pedalbaord.
I use normally-open reed switches, a teensy 3.5, the Arduino IDE with teensy add on and as midi software to link the Microcontroller-Input to my laptop's speakers I use MIDI-OX.
I spent couple of days watching tutorials, trying to understand suitable Arduino C++ coding examples, which worked out preatty well and now I am about to successfully fail in trying to adapt them to my needs.
It feels like it should be such a short and straightforward simple code, since it just needs to do the following:
• constantly reading the digital input pins, that are connected to normally open reed switches;
• Once a reed switch is being detected to be closed,
- Switch Debouncing should prevent “bouncing” over 5ms
- A usbMidisendNoteOn command should make a to a laptop connected speaker to sound a specific note, at a specific velocity/loudness, on a specific midi output channel
- The onboard led should switch on
• Once this reed switch is being detected to be opened,
- Switch Debouncing should prevent “bouncing” over 5ms
- A usbMidisendNoteOff command should make a to the laptop connected speaker to stop sounding this note
- The onboard led should switch off
That's it. Here is my attempt.
I checked the midi software, the hardware setup works, too... but with this following code I just get the proper Led reaction, but the note is missing...
const int REED_PIN = 2; // Pin connected to reed switch
const int LED_PIN = 13; // LED pin - active-high
void setup() {
pinMode(REED_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int proximity = digitalRead(REED_PIN); // Read the state of the switch
if (proximity == LOW) // If the pin reads low, the switch is closed.
{
usbMIDI.sendNoteOn(36, 99, 1); // 60 = C4
digitalWrite(LED_PIN, HIGH); // Turn the LED on
}
else {
usbMIDI.sendNoteOff(36, 0, 1); // 60 = C4
digitalWrite(LED_PIN, LOW); // Turn the LED off
}
}
I would be really glad if you guys could tell me, what I am doing wrong here and point me in the right direction.