void idle(void) { color_t c; uint8_t animate = 0; uint32_t t = 0; cli(); if (g_sync_count >= g_sync_divisor) { g_sync_count = 0; animate = 1; } sei(); if (animate) { cli(); t = g_pattern_t++; sei(); // do some animation! led_pattern_next(t, &c); set_led_rgb(c.red, c.green, c.blue); } flush_saved_tick_count(0); }
void idle(void) { color_t c; uint8_t animate = 0, current_state = 0, button_state_changed = 0; uint32_t t = 0; cli(); if (g_sync_count >= g_sync_divisor) { g_sync_count = 0; animate = 1; } // read button state & check time if (g_button_time > 0 && g_time >= g_button_time) { current_state = g_button_state; g_button_time = 0; button_state_changed = 1; } sei(); // Set the leds and motor speed accordingly when button is pressed if (button_state_changed) { if (current_state) set_motor_speed(255, 1); else set_motor_speed(0, 1); } // run the animation if the current state if (animate) { cli(); t = g_pattern_t++; sei(); // do some animation! led_pattern_next(t, &c); set_led_rgb(c.red, c.green, c.blue); } flush_saved_tick_count(0); }