kitt.c (2010B)
1 /* Copyright 2022 HorrorTroll <https://github.com/HorrorTroll> 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 // variable for startup animation 18 bool BASE_EFFECT_NOT_STARTED_YET = true; 19 uint8_t base_effect_startup_counter = 255; 20 21 uint8_t led_count = 10; 22 uint8_t led_first = 7; 23 24 static uint8_t time_to_led(uint8_t time, uint8_t led_behind) { 25 uint16_t led_time = led_count * time; 26 uint16_t step = ((2 * led_count + (led_time / 128)) - led_behind) % (2 * led_count); 27 uint8_t led; 28 29 if (step < led_count) { 30 led = step; 31 } else { 32 led = led_count - 1 - (step - led_count); 33 } 34 35 return led; 36 } 37 38 static hsv_t KITT_math(hsv_t hsv, uint8_t i, uint8_t time) { 39 40 // reset base effect startup 41 if (i == 0) { 42 BASE_EFFECT_NOT_STARTED_YET = true; 43 } 44 45 hsv.h = 0; 46 hsv.s = 255; 47 48 if (i >= led_first && i < led_first + led_count) { 49 uint8_t j = i - led_first; 50 if (j == time_to_led(time, 0)) { 51 hsv.v = hsv.v; 52 } else if (j == time_to_led(time, 1)) { 53 hsv.v = hsv.v/2; 54 } else if (j == time_to_led(time, 2)) { 55 hsv.v = hsv.v/4; 56 } else if (j == time_to_led(time, 3)) { 57 hsv.v = hsv.v/8; 58 } else { 59 hsv.v = 0; 60 } 61 } else { 62 hsv.v = 0; 63 } 64 65 return hsv; 66 } 67 68 bool KITT(effect_params_t* params) { return effect_runner_i(params, &KITT_math); }