Skip to content

Instantly share code, notes, and snippets.

@OttoWinter
Last active May 11, 2018 13:57
Show Gist options
  • Save OttoWinter/a50c4ce34e50586f70866fbe652e75fe to your computer and use it in GitHub Desktop.
Save OttoWinter/a50c4ce34e50586f70866fbe652e75fe to your computer and use it in GitHub Desktop.
#define NUM_LEDS 60
class FastLEDLightOutput : public Component, public LightOutput {
public:
FastLEDLightOutput() {
// supports brightness and RGB
traits_ = LightTraits(true, true, false);
}
const LightTraits &get_traits() const override {
return traits_;
}
void loop() override {
auto values = this->get_state()->get_current_values();
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].r = values.get_red() * values.get_brightness() * values.get_state() * 255;
leds[i].g = values.get_green() * values.get_brightness() * values.get_state() * 255;
leds[i].b = values.get_blue() * values.get_brightness() * values.get_state() * 255;
}
FastLED.show();
}
void setup() override {
FastLED.addLeds<NEOPIXEL, 6>(leds, NUM_LEDS);
}
LightTraits traits_;
CRGB leds[NUM_LEDS];
};
void setup() {
// other setup code
// ...
auto *out = App.register_component(new FastLEDLightOutput());
auto *state = App.register_component(new LightState("Outdoor Lights", out->get_traits()));
App.register_light(state);
out->set_state(state);
App.setup();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment