Skip to content

Instantly share code, notes, and snippets.

@theVDude
Created December 6, 2017 06:38
Show Gist options
  • Save theVDude/3366f258ddcb1acb95cae2f3fcb38f23 to your computer and use it in GitHub Desktop.
Save theVDude/3366f258ddcb1acb95cae2f3fcb38f23 to your computer and use it in GitHub Desktop.
void rgblight_effect_breathing_xmas(uint8_t interval) {
static uint16_t current_hue = 0;
static uint8_t pos = 0;
static uint16_t last_timer = 0;
float val;
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) {
return;
}
last_timer = timer_read();
// http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E));
rgblight_sethsv_noeeprom(current_hue, rgblight_config.sat, val);
if (pos == 0) {
if (current_hue == 0){
current_hue = 120;
} else {
current_hue = 0;
}
}
pos = (pos + 1) % 256;
}
@theVDude
Copy link
Author

theVDude commented Dec 6, 2017

lines 17-21 can be stuck in a ternary operator but i don't know how to use them in c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment