Lights are easy in Rack plugins.
Define the light ID in your MyModule
class.
enum LightIds {
CLOCK_LIGHT,
NUM_LIGHTS
};
Set the light value in your MyModule::process()
method between 0.0 (off) and 1.0 (fully on).
void process(const ProcessArgs& args) override {
bool clock = isClocked();
lights[CLOCK_LIGHT].setBrightness(clock ? 1.f : 0.f);
}
Add the light widget to your panel in MyModuleWidget()
.
addChild(createLightCentered<MediumLight<RedLight>>(mm2px(Vec(10.0, 10.0)), module, MyModule::CLOCK_LIGHT));
Multicolored lights
For lights with multiple colors, use adjacent light IDs for each of the colors. This is similar to how physical RGB LEDs work using multiple leads.
enum LightIds {
ENUMS(RGB_LIGHT, 3), // This reserves 3 "enum slots" rather than just 1
NUM_LIGHTS
};
...
void process(const ProcessArgs& args) override {
lights[RGB_LIGHT + 0].setBrightness(red);
lights[RGB_LIGHT + 1].setBrightness(green);
lights[RGB_LIGHT + 2].setBrightness(blue);
}
...
addChild(createLightCentered<MediumLight<RedGreenBlueLight>>(mm2px(Vec(10.0, 10.0)), module, MyModule::RGB_LIGHT));