diff --git a/ATtiny84_LED_PC.c b/ATtiny84_LED_PC.c index 2b9079a..96bd254 100644 --- a/ATtiny84_LED_PC.c +++ b/ATtiny84_LED_PC.c @@ -72,7 +72,7 @@ uint64_t old_time_ms = 0; // ms Counter Func ISR(TIM1_CAPT_vect) { - ms += 100; + ms += 10; } // NeoPixel Funcs @@ -132,41 +132,52 @@ uint8_t led2_idx = 0; uint8_t led3_idx = 0; uint8_t colour = 0; uint8_t func_idx = 0; -uint8_t btn_old_state = 1; +uint8_t btn_old_state = 0; uint8_t colour_state = STATE_SUN_MOON; uint8_t current_state; int main() { + uint8_t show; + init(); // Main loop while(1) { - if (ms > led_ms_update[0]) + show = 0; + + if (ms >= led_ms_update[0]) { - led_ms_update[0] = ms + LED0_MS; + led_ms_update[0] += LED0_MS; func_list[func_idx](LED0_COUNT, &led0_idx, colour, 0); + show = 1; } - if (ms > led_ms_update[1]) + if (ms >= led_ms_update[1]) { - led_ms_update[1] = ms + LED1_MS; + led_ms_update[1] += LED1_MS; func_list[func_idx](LED1_COUNT, &led1_idx, colour, 1); + show = 1; } - if (ms > led_ms_update[2]) + if (ms >= led_ms_update[2]) { - led_ms_update[2] = ms + LED2_MS; + led_ms_update[2] += LED2_MS; func_list[func_idx](LED2_COUNT, &led2_idx, colour, 2); + show = 1; } - if (ms > led_ms_update[0]) + if (ms >= led_ms_update[3]) { - led_ms_update[3] = ms + LED3_MS; + led_ms_update[3] += LED3_MS; func_list[func_idx](LED3_COUNT, &led3_idx, colour, 3); + show = 1; } - show_leds(); + if (show) + { + show_leds(); + } #ifdef ENABLE_OLED if (ms - 1000 >= old_time_ms) @@ -413,7 +424,7 @@ inline void send_byte(uint8_t byte, uint8_t led) byte <<= 1; } } - + inline void send_pixel(uint8_t r, uint8_t g, uint8_t b, uint8_t led) { cli(); @@ -447,9 +458,9 @@ void init() init_display(); #endif - // TIM1 init - prescaler 64 - TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11) | (1 << CS10); - ICR1 = (F_CPU / 64 / 100) - 1; + // TIM1 init - CTC - prescaler 8 - 10ms interrupt + TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11); + ICR1 = (F_CPU / 8 / 100) - 1; TIMSK1 = (1 << ICIE1); sei(); }