Hi there,
I'm currently at the very very early stages of making my own LED MIDI reactive strip so that when a key is pressed on the piano then an LED (will eventually be 2 LEDs) will light up.
So far I've managed to get a simple MIDI read document working with my DAW and I'm getting the notes going from my piano into the DAW and then sent out to my Arduino board (using an Arduino Pro Micro Leonardo).
Next I've been trying to get just one LED to light up whenever a key is pressed on the piano by placing some code (using the FastLEDS library) into the noteOn function and was hoping that whenever (at this point) any key is pressed that the first LED would light up.
That's unfortunately not happening though. If I take this code from the noteOn function :
leds[0] = CRGB::Red;
FastLED.show();
and place it into say just for now the setup function then the first LED does indeed light up however that code never fires when it's placed inside the noteOn function
I'm very new to Arduino and coding so not really too sure what I'm missing. It's probably going to be something very easy somewhere but I've been moving code back and forth for hours now and seem to be able to get LEDs to light up every which way except for when I want them to light up!
If anyone could possibly point me in the right direction as to why the LED code isn't firing when placed in the noteOn function then I'd be very greatful.
My full code currently is below :
/*
MIDIUSB_test.ino
Created: 4/6/2015 10:47:08 AM
Author: gurbrinder grewal
Modified by Arduino LLC (2015)
*/
#include "MIDIUSB.h"
#include "FastLED.h"
#define NUM_LEDS 2 // # of LEDS in the strip
CRGB leds[NUM_LEDS];
#define PIN 3 // Output Pin to Data Line on Strip
#define COLOR_ORDER GRB // I had to change this for my strip if your color is off then you know.
int fadeAmount = 5; // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
int brightness = 0;
void setup() {
// sanity check delay - allows reprogramming if accidently blowing power w/leds
delay(2000);
FastLED.addLeds<WS2812, PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
Serial.begin(115200);
}
// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
void loop() {
midiEventPacket_t rx;
do {
rx = MidiUSB.read();
if (rx.header != 0) {
Serial.print("Received: ");
Serial.print(rx.header, HEX);
Serial.print("-");
Serial.print(rx.byte1, HEX);
Serial.print("-");
Serial.print(rx.byte2, HEX);
Serial.print("-");
Serial.println(rx.byte3, HEX);
}
} while (rx.header != 0);
}
// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).
void noteOn(byte channel, byte pitch, byte velocity) {
// Turn the first LED on the strip on
leds[0] = CRGB::Red;
FastLED.show();
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
// Now turn the LED off
leds[0] = CRGB::Black;
FastLED.show();
}
Many thanks for any help anyone can throw my way on this.
Best wishes,
Mark