commit
6ae4d92da0
@ -0,0 +1,51 @@
|
|||||||
|
# Kaleidoscope-LEDEffect-Rainbow
|
||||||
|
|
||||||
|
Two colorful rainbow effects are implemented by this plugin: one where the
|
||||||
|
rainbow waves through the keys, and another where the LEDs breathe though the
|
||||||
|
colors of a rainbow. The difference is that in the first case, we have all the
|
||||||
|
rainbow colors on display, and it waves through the keyboard. In the second
|
||||||
|
case, we have only one color at a time, for the whole board, and the color
|
||||||
|
cycles through the rainbow's palette.
|
||||||
|
|
||||||
|
## Using the extension
|
||||||
|
|
||||||
|
To use the plugin, include the header, and tell the firmware to use either (or
|
||||||
|
both!) of the effects:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#include <Kaleidoscope-LEDControl.h>
|
||||||
|
#include <Kaleidoscope-LEDEffect-Rainbow.h>
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(LEDRainbowEffect, LEDRainbowWaveEffect);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Kaleidoscope.setup();
|
||||||
|
|
||||||
|
LEDRainbowEffect.brightness(150);
|
||||||
|
LEDRainbowWaveEffect.brightness(150);
|
||||||
|
LEDRainbowWaveEffect.update_delay(50);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Plugin methods
|
||||||
|
|
||||||
|
The plugin provides two objects: `LEDRainbowEffect`, and `LEDRainbowWaveEffect`,
|
||||||
|
both of which provide the following methods:
|
||||||
|
|
||||||
|
### `.brightness([brightness])`
|
||||||
|
|
||||||
|
> Sets (or gets, if called without an argument) the LED brightness for the
|
||||||
|
> effect.
|
||||||
|
>
|
||||||
|
> Defaults to 50.
|
||||||
|
|
||||||
|
### `.update_delay([delay])`
|
||||||
|
|
||||||
|
> Sets (or gets, if called without an argument) the number of milliseconds
|
||||||
|
> between effect updates. Smaller number results in faster rainbows.
|
||||||
|
>
|
||||||
|
> Defaults to 40.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
* [Kaleidoscope-LEDControl](LEDControl.md)
|
@ -0,0 +1,19 @@
|
|||||||
|
/* Kaleidoscope-LEDEffect-Rainbow - Rainbow LED effects for Kaleidoscope.
|
||||||
|
* Copyright (C) 2017-2018 Keyboard.io, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "kaleidoscope/plugin/LEDEffect-Rainbow.h"
|
@ -0,0 +1,84 @@
|
|||||||
|
/* Kaleidoscope-LEDEffect-Rainbow - Rainbow LED effects for Kaleidoscope.
|
||||||
|
* Copyright (C) 2017-2018 Keyboard.io, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Kaleidoscope-LEDEffect-Rainbow.h"
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
void LEDRainbowEffect::update(void) {
|
||||||
|
uint16_t now = millis();
|
||||||
|
if ((now - rainbow_last_update) < rainbow_update_delay) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
rainbow_last_update = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
cRGB rainbow = hsvToRgb(rainbow_hue, rainbow_saturation, rainbow_value);
|
||||||
|
|
||||||
|
rainbow_hue += rainbow_steps;
|
||||||
|
if (rainbow_hue >= 255) {
|
||||||
|
rainbow_hue -= 255;
|
||||||
|
}
|
||||||
|
::LEDControl.set_all_leds_to(rainbow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LEDRainbowEffect::brightness(byte brightness) {
|
||||||
|
rainbow_value = brightness;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LEDRainbowEffect::update_delay(byte delay) {
|
||||||
|
rainbow_update_delay = delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------
|
||||||
|
|
||||||
|
void LEDRainbowWaveEffect::update(void) {
|
||||||
|
uint16_t now = millis();
|
||||||
|
if ((now - rainbow_last_update) < rainbow_update_delay) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
rainbow_last_update = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
|
uint16_t key_hue = rainbow_hue + 16 * (i / 4);
|
||||||
|
if (key_hue >= 255) {
|
||||||
|
key_hue -= 255;
|
||||||
|
}
|
||||||
|
cRGB rainbow = hsvToRgb(key_hue, rainbow_saturation, rainbow_value);
|
||||||
|
::LEDControl.setCrgbAt(i, rainbow);
|
||||||
|
}
|
||||||
|
rainbow_hue += rainbow_wave_steps;
|
||||||
|
if (rainbow_hue >= 255) {
|
||||||
|
rainbow_hue -= 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LEDRainbowWaveEffect::brightness(byte brightness) {
|
||||||
|
rainbow_value = brightness;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LEDRainbowWaveEffect::update_delay(byte delay) {
|
||||||
|
rainbow_update_delay = delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kaleidoscope::plugin::LEDRainbowEffect LEDRainbowEffect;
|
||||||
|
kaleidoscope::plugin::LEDRainbowWaveEffect LEDRainbowWaveEffect;
|
@ -0,0 +1,77 @@
|
|||||||
|
/* Kaleidoscope-LEDEffect-Rainbow - Rainbow LED effects for Kaleidoscope.
|
||||||
|
* Copyright (C) 2017-2018 Keyboard.io, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Kaleidoscope-LEDControl.h"
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
class LEDRainbowEffect : public LEDMode {
|
||||||
|
public:
|
||||||
|
LEDRainbowEffect(void) {}
|
||||||
|
|
||||||
|
void brightness(byte);
|
||||||
|
byte brightness(void) {
|
||||||
|
return rainbow_value;
|
||||||
|
}
|
||||||
|
void update_delay(byte);
|
||||||
|
byte update_delay(void) {
|
||||||
|
return rainbow_update_delay;
|
||||||
|
}
|
||||||
|
void update(void) final;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint16_t rainbow_hue = 0; // stores 0 to 614
|
||||||
|
|
||||||
|
uint8_t rainbow_steps = 1; // number of hues we skip in a 360 range per update
|
||||||
|
uint16_t rainbow_last_update = 0;
|
||||||
|
uint16_t rainbow_update_delay = 40; // delay between updates (ms)
|
||||||
|
|
||||||
|
byte rainbow_saturation = 255;
|
||||||
|
byte rainbow_value = 50;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class LEDRainbowWaveEffect : public LEDMode {
|
||||||
|
public:
|
||||||
|
LEDRainbowWaveEffect(void) {}
|
||||||
|
|
||||||
|
void brightness(byte);
|
||||||
|
byte brightness(void) {
|
||||||
|
return rainbow_value;
|
||||||
|
}
|
||||||
|
void update_delay(byte);
|
||||||
|
byte update_delay(void) {
|
||||||
|
return rainbow_update_delay;
|
||||||
|
}
|
||||||
|
void update(void) final;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint16_t rainbow_hue = 0; // stores 0 to 614
|
||||||
|
|
||||||
|
uint8_t rainbow_wave_steps = 1; // number of hues we skip in a 360 range per update
|
||||||
|
uint16_t rainbow_last_update = 0;
|
||||||
|
uint16_t rainbow_update_delay = 40; // delay between updates (ms)
|
||||||
|
|
||||||
|
byte rainbow_saturation = 255;
|
||||||
|
byte rainbow_value = 50;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern kaleidoscope::plugin::LEDRainbowEffect LEDRainbowEffect;
|
||||||
|
extern kaleidoscope::plugin::LEDRainbowWaveEffect LEDRainbowWaveEffect;
|
Loading…
Reference in new issue