What is the simplest way to set a new default LED color

I haven’t had any trouble tweaking and downloading the layout. I’m sure I could puzzle my way through the LED options (including plugins). But I’d rather get expert opinion.

I just want to be able to start up the keyboard with a different default (one of the existing options we get by repeatedly tapping the LED key) – rather than LEDs off.

–Jed

The order that the LED plugins are listed in the Kaleioscope.use(...) bit are the order that they’ll be used in, so just make sure that the effect you want is listed before the other LED effects.

The mode you want is represented by an object passed into the use() function.

To get a certain mode to activate by default, simply call the .activate() method on that object.

For example, if you want solid red to activate, put as the last line in the setup() method: solidRed.activate();. I believe the default listed is LEDOff.activate(), so you want to comment out or remove that line, too.

1 Like

Thanks Ben! That worked! Very glad I asked.

Out of curiosity: How does the LED key step through part of this list (but not all of it)? Or more usefully, where is the code that does that?

Plugins that implement a LED mode derive from the LEDMode class, which registers the LED mode in its default begin method, which adds the mode to an array. The next/prev just steps through this array, relevant code is here.

1 Like

Thanks. Everything except some parts of the initialization make sense to me.

However… it turns out that I was premature in saying “That works!” After uploading the correct color comes up immediately. On power cycling however it does not. By screwing around with initialization order I figured out that (a) the initial LEDMode is correctly set by activate(), but (b) on power up the LEDs are set to off (0,0,0) and only by going around the cycle once can I get the actual color. So somehow the LEDs are forced off by the power on process.

I didn’t notice this because with the activate fix the LEDs are on with the right color immediately. Power up with no new boot load must take a different path.

Possibly the issue is the first line of LEDControl::begin, which is “set_all_leds_to({0, 0, 0});” but since I don’t know what else is going on at that point I don’t want to screw things up by changing that…

The default is to switch to the LEDOff mode first. this is partially a failsafe in case the host device can’t or won’t give us enough power for the LEDs. I wanted to make sure that you don’t get into a situation where your keyboard crashes on boot or is disabled by the computer because it’s too greedy.

You might take a look at how I am doing LED control in my sketch:

Specifically, take a look at the static void turnLedsOnAndOff(uint8_t key_state){ ... } and static void nextPrevLedMode(uint8_t key_state, bool skipOff) { ... } and the associated MACRO_LED_NEXT_PREV and MACRO_LED_ON_AND_OFF that I’m using. In my case, I have the LEDs turned off on boot, tapping the LED button toggles on and off (defaulting to your specified default one), and fn+led and fn+shift+led toggle forward and backward through the led modes (skipping the off mode).

That might be a good starting point for you to get you closer to what you want?