hey. i'm controlling an LPD8806 via FastLED and the Arduino Midi library,

hey. i’m controlling an LPD8806 via FastLED and the Arduino Midi library, where led[i] = midi note on[x] and r/g/b are controlled by 3 midi CCs. i am able to create chasers, cylons, etc and change their color.

however, i have been stumped by something that will probably be simple for you guys. once an LED has been turned on by a NOTEON, i don’t know how to update it with new RGB information. i see you guys using a lot of for(i++) loops, but i don’t know if that will work in my application.

in short, let’s say an LED is turned on and held: i want it to continue to reference my r, g, and b values and update accordingly.

here’s what happens when arduino receives a midi note on and a note off:

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
if(pitch < NUM_LEDS){
leds[pitch].setRGB(ccR, ccG, ccB); //where ccX refers to 0-255 cc values
FastLED.show();
}
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
if(pitch < NUM_LEDS){
leds[pitch] = CRGB::Black;
FastLED.show();
}
}

in this case, my LEDs are only changing color when a noteon is received. i want the LED to continue to reference ccX to get RGB info in between noteon and noteoff. how might i do this, when the contents of “void HandleNoteOn” seem to be triggered by a one-off event?

note that if i have my RGB values fluctuating via an LFO applied to each CC, AND a midi sequence programmed to behave like a “chaser” ala various examples, the LEDs DO update…but only because i am triggering new noteons.

thanks for your time, please let me know if i can clarify further.

I only partially understand how MIDI works. Can you explain what MIDI info (if any) is being sent while (for example) you held a note for five seconds?
While the note is held (still On), is MIDI data changing? Is the corresponding pixel not staying On, or should it be changing in some fashion while it’s being held for that five seconds?

thanks for your response. on the phone and waking so apologies for brevity.

note ons and offs are single messages with nothing in between. think of that void handle note on function as if it were an if statement…

corresponding pixil stays on til note off, which is desired

Um, is this all your code?

The led should remain lit until it is turned black with the note off info. I can’t see anything in that short snippet to suggest why its doing what you describe.

Can we see the rest of your code?

thanks for your response. this is all the relevant code. I think you’re misunderstanding. it’s not an issue of remaining lit, the pixil stays lit as long as the note is held. it is not, however, updating its color until a subsequent note on is received and the rgb CCS are polled again

Ah!
OK. So you effectively update the LEDs colour in the background, but it will not display your change until you issue a FastLED.show() or a FastLED.delay()

Ok, so if I understand this correctly, ccR, and/or ccG, and/or ccB can be updated by one of the 3 midi CCs while the note is still On, but since it’s already On, it’s not going through handleNoteOn function, thus not changing.

Maybe you can store another array (length of NUM_LEDS) and save the state of the pixel, On or Off. Then have a check to see if the pixel is On. If it is On, then update the ccX as needed.

marc, that is correct. i was definitely thinking about a bool array. i’ll give that a shot tomorrow. a followup question…how would i concisely check the entire array for true values without x number of if statements? i know this is veering more into standard c++ education and not FastLED but if you’d care to lead me in the right direction i can get there on my own.

Stuart, i didn’t see a fastled.delay() in the documentation but i’ll look for it again. is this like arduino’s native delay() in that it stops the program? as this is midi triggered, i can’t have the program lock up in a delay state while it is supposed to be receiving messages.

i was also considering forcing a fastled.show if ccX != last ccX but that seems to be getting messy.

Lewis, I’m still learning a lot about C++ myself so I can’t really help with higher level or fancy C++ code. :slight_smile:

How many LEDs are in your project?
Is it too slow to loop through the whole LED bool array checking On/Off state each time around your arduino’s main loop? There may well be a much more efficient/elegant way to do this, but I’d just try it and start there and see how it runs.

If you add this at the bottom of your main loop, what sort of frame rate are you getting? How much does it drop if you suddenly play a bunch of notes or tweak the CCs all at once?
Serial.print("FPS: "); Serial.println(LEDS.getFPS()); // Display FPS in serial monitor

only 16 individual LEDs this time so it definitely won’t be too much to check the array. but i do want to try to do this efficiently when i create something with the rest of the 16 ft of LPD8806 i bought haha.

unfortunately i can’t easily use the serial monitor because the midi to serial interface (hairlessmidi) hogs the serial connection, and since the midi needs to come in over serial it’s either one or the other heheh.

however, i oscillated the RGB signals pretty fast (sending a lot of data) and blasted the noteons for all 16 leds at 32nd note intervals (very fast) and it all updated just fine, so it should be good enough to get advice on from better programmers than i.

thanks a lot for your help! i love finding active libraries, as opposed to being this guy: http://imgs.xkcd.com/comics/wisdom_of_the_ancients.png

Ah, serial already tied up for MIDI. I understand. Perhaps if you do want to guesstimate at how fast it’s looping you can do something like compare previous and current millis times each time you loop and if the time is less then some amount you choose, then turn on the onboard LED (pin 13 on an UNO, or whatever MCU you’re using if it has an onboard LED). You can then change the “cutoff time” you pick up or down a bit until you get a sense of where where your time check is triggering.

[I just learned that if you’re using an Arduino Mega then you get 4 serial monitors! Mega-licious.]

Love xkcd.

Hi lewis,

midi is clocked at 31250, and in that respect, its fairly slow. so you may be able to afford more delay than you think.
FastLED.delay() can be used inplace of the Arduino delay() function, except that while it will delay execution at that point, it will continue to update the pixels. However calling FastLed.delay() causes a FastLED.show();

I’m interested in how all this works in concert (no pun intended).

I’ve previously built light controllers that used CCs (Control Change messages) but i don’t recall using the note on /note off message in that project. So i’m interested in how you would use this in a performance. Is the strip going to be controlled from a sequenced track the audience don’t hear?

I’m not familiar with the midi library you have used, but rather than just call FastLED.show() on note on/off message can you call update the pixel info and FastLED.show() on receive of a CC?

While i think about it, couldn’t you send a SysEx with the FPS in it?

hey Stuart, thanks for the followup. apologies for a long reply, i just got my coffee.

Midi over Serial using Hairlessmidi is limited to 256000 baud and i’m running at 115200. still should be enough for a 16 LED project especially if i find a sweet spot and quantize the incoming CC data to a lower resolution. i will be playing with fastLED delay today.

a little background on the project – and now that i see how many people are involved here, i’ll definitely be posting the result – i’m lining the sides of a bowl-sized broken magnifying lens that has cracked. picture a jellyfish that has washed up on the beach – that’s what it looks like. shining LEDs into the sides really makes the cracked fissures POP and glow beautifully, especially when the lights go in a circle around it. it’s breathtaking.

i too have controlled LED groups from arduino using CCs and TIP120s. i’ve found that as a self taught, stubborn as hell programmer, i’m much much better at writing out “light programs” using my MIDI controllers/sequencers rather than C++. furthermore, my music already essentially contains a lightshow – it’s just a matter of tying the existing midi to the LEDs.

the note ons represent the number of LEDs. in my case, notes 1-16 (0 intentionally omitted for sanity/systemic purposes as an “all notes off”) will represent leds 1-16. velocity might control fadeout, if applicable. this way, i can use MIDI to write all of the fancy light stuff i’ve seen people program directly into their microprocessors…fire, ice shards, bio-luminescence…all much easier to write using ccs and noteons!

i’ll try moving the fastLEDshow action to the CC handler function. the newer version of the arduino midi library is pretty great. here’s the example sketch i’m drawing from. the difficulty is that all of the action occurs outside void loop, in individual functions triggered by specific incoming events. this requires some use of global variables in order for the functions to interact with one another.

you lost me a little bit with the sysex and fps. i was reading last night about how to make arduino follow midi clock (or at least extract a tempo from it. i’m going to be calculating tempo synced delays (millis based so as not to lock the pgm) using midi clock from my host.

Wow, thats sounds like a great project.

I’ve never heard of hairless midi, is it this? http://projectgus.github.io/hairless-midiserial/

if so, their docs say it supports sysex.

sysex allowed midi equipment manufactures to send “other data” over midi. Thats how we transferred tone banks back in the day.

So you could use a sysex message to send your FastLED FPS back to a PC whatever, and read that info (or other diagnostics) out there.

Keep us posted.

ahhh it’s working so well using the bool array. everything is behaving as i desired to begin with. i’m so happy.

stuart, yeah that’s the one. seemed simpler than building a midi input. thanks for the sysex tip, that will definitely make for easier tempo messages and debug info!!

i have learned so much from this support thread, thank you all.

Hi VERY new to FastLED, lean a lot for the last few days. this is amazing. need help and more information on using multiple arrays of WS2801 on one Arduino . such as how to get different colors and patterns on different arrays. Examples helped a lot but need more information to takes things further, planing to have a very cool LED display with approximately 4500 LEDs any help on the right direction is much appreciated.

Hi @Chithru_Mihiripenna ​, please start a new thread, and give us as much information as you can. Thank you.

Hi Stuart
thanks for the reply. tried but could not get around to open a new thread. I like to find some examples done with multiple WS2801 strings running from one arduino please.
thanks.