116 lines
2.2 KiB
C
116 lines
2.2 KiB
C
#include "led_effects.h"
|
||
#include "led_driver.h"
|
||
#include "freertos/FreeRTOS.h"
|
||
#include "freertos/task.h"
|
||
#include <stdlib.h>
|
||
#include <time.h>
|
||
|
||
void led_all_on(uint8_t r, uint8_t g, uint8_t b)
|
||
{
|
||
int n = led_get_count();
|
||
for (int i = 0; i < n; i++) {
|
||
led_set_pixel(i, r, g, b);
|
||
}
|
||
led_show();
|
||
}
|
||
|
||
void led_all_off(void)
|
||
{
|
||
led_clear();
|
||
led_show();
|
||
}
|
||
|
||
void led_idle_animation(void)
|
||
{
|
||
static int pos = 0;
|
||
int n = led_get_count();
|
||
if (n <= 0) return;
|
||
|
||
for (int i = 0; i < n; i++)
|
||
led_set_pixel(i, 0, 0, 0);
|
||
|
||
// pontinho azul
|
||
led_set_pixel(pos, 0, 0, 16);
|
||
led_show();
|
||
|
||
pos = (pos + 1) % n;
|
||
vTaskDelay(pdMS_TO_TICKS(50));
|
||
}
|
||
|
||
void led_jackpot_animation(void)
|
||
{
|
||
static int state = 0;
|
||
static int step = 0;
|
||
int n = led_get_count();
|
||
|
||
if (state == 0) {
|
||
// Piscas laranja
|
||
for (int i = 0; i < n; i++)
|
||
led_set_pixel(i, (step & 1) ? 32 : 0, (step & 1) ? 16 : 0, 0);
|
||
|
||
led_show();
|
||
|
||
step++;
|
||
if (step >= 12) { // 6 ON + 6 OFF
|
||
step = 0;
|
||
state = 1;
|
||
}
|
||
}
|
||
|
||
else if (state == 1) {
|
||
// Arco-íris progressivo
|
||
for (int i = 0; i < n; i++) {
|
||
int x = (i + step) % n;
|
||
uint8_t r = (x * 5) & 0xFF;
|
||
uint8_t g = ((x * 3) & 0xFF) >> 1;
|
||
uint8_t b = ((x * 7) & 0xFF) >> 2;
|
||
led_set_pixel(i, r, g, b);
|
||
}
|
||
|
||
led_show();
|
||
|
||
step++;
|
||
if (step >= n * 2) {
|
||
step = 0;
|
||
state = 0; // repete a animação
|
||
}
|
||
}
|
||
}
|
||
|
||
void led_clock_animation(void)
|
||
{
|
||
int n = led_get_count();
|
||
if (n <= 0) return;
|
||
|
||
time_t now;
|
||
struct tm timeinfo;
|
||
|
||
time(&now);
|
||
localtime_r(&now, &timeinfo);
|
||
|
||
int h = timeinfo.tm_hour % 12;
|
||
int m = timeinfo.tm_min;
|
||
int s = timeinfo.tm_sec;
|
||
|
||
int pos_h = (h * n) / 12;
|
||
int pos_m = (m * n) / 60;
|
||
int pos_s = (s * n) / 60;
|
||
|
||
led_clear();
|
||
|
||
// HORAS – verde forte
|
||
led_set_pixel(pos_h, 10, 40, 10);
|
||
|
||
// MINUTOS – azul
|
||
led_set_pixel(pos_m, 10, 10, 60);
|
||
|
||
// SEGUNDOS – branco muito suave
|
||
led_set_pixel(pos_s, 5, 5, 5);
|
||
|
||
led_show();
|
||
|
||
|
||
vTaskDelay(pdMS_TO_TICKS(200));
|
||
}
|
||
|