Merge pull request #4 from keyboardio/h/timer-based-update

Use timers instead of ticks to time when to update the effects
pull/365/head
Gergely Nagy 6 years ago committed by GitHub
commit 48927e5ccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,10 +3,11 @@
namespace kaleidoscope {
void LEDRainbowEffect::update(void) {
if (rainbow_current_ticks++ < rainbow_ticks) {
uint16_t now = millis();
if ((now - rainbow_last_update) < rainbow_update_delay) {
return;
} else {
rainbow_current_ticks = 0;
rainbow_last_update = now;
}
cRGB rainbow = hsvToRgb(rainbow_hue, rainbow_saturation, rainbow_value);
@ -26,10 +27,11 @@ void LEDRainbowEffect::brightness(byte brightness) {
// ---------
void LEDRainbowWaveEffect::update(void) {
if (rainbow_current_ticks++ < rainbow_wave_ticks) {
uint16_t now = millis();
if ((now - rainbow_last_update) < rainbow_update_delay) {
return;
} else {
rainbow_current_ticks = 0;
rainbow_last_update = now;
}
for (uint8_t i = 0; i < LED_COUNT; i++) {

@ -15,8 +15,8 @@ class LEDRainbowEffect : public LEDMode {
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_current_ticks = 0;
uint16_t rainbow_ticks = 10; // delays between 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;
@ -34,8 +34,8 @@ class LEDRainbowWaveEffect : public LEDMode {
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_current_ticks = 0;
uint16_t rainbow_wave_ticks = 10; // delays between 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;

Loading…
Cancel
Save