LED_shit/main/led_effects.c
2025-11-23 18:15:56 +00:00

176 lines
3.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "led_effects.h"
#include "led_driver.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <stdlib.h>
#include <time.h>
#include "mqtt_comandos.h"
#include "premios.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));
}
void led_anim_03(void)
{
static int left = 0;
static int right = LED_COUNT - 1;
static bool meet = false;
int n = LED_COUNT;
// ------- Lista de prémios -------
// coloca as posições reais depois
static const int premios[] = { 3, 8, 15, 22, 31, 40, 47, 53 };
static const int total_premios = sizeof(premios) / sizeof(premios[0]);
// limpar tudo primeiro
led_clear();
if (!meet) {
// acende esquerda e direita
led_set_pixel(left, 0, 40, 0); // verde
led_set_pixel(right, 0, 40, 0);
left++;
right--;
// encontraram-se?
if (left >= right) {
meet = true;
}
}
else {
// ---- PISCAR PRÉMIOS ----
static bool on = false;
on = !on;
for (int i = 0; i < total_premios; i++) {
int p = premios[i] % n;
if (on)
led_set_pixel(p, 0, 0, 60); // azul forte
else
led_set_pixel(p, 0, 0, 10); // azul fraco
}
// durante alguns ciclos pisca antes de resetar
static int count = 0;
count++;
if (count > 20) { // ajusta aqui a duração do piscar
count = 0;
meet = false;
left = 0;
right = n - 1;
}
}
led_show();
vTaskDelay(pdMS_TO_TICKS(50));
}