166 lines
3.5 KiB
C
166 lines
3.5 KiB
C
#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"
|
|
#include "display.h" // onde está a tua display_number()
|
|
|
|
|
|
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)
|
|
{
|
|
time_t now = time(NULL);
|
|
struct tm t;
|
|
localtime_r(&now, &t);
|
|
|
|
int h = t.tm_hour;
|
|
int m = t.tm_min;
|
|
int s = t.tm_sec;
|
|
|
|
// Mostrar HHMM no display (14-seg)
|
|
display_set_time(h, m);
|
|
|
|
// LED dos segundos em azul
|
|
led_clear(); // APAGA TUDO
|
|
|
|
int pos = s % LED_COUNT; // 0..59 ou 0..63
|
|
|
|
led_set_pixel(pos, 0, 0, 60); // azul forte
|
|
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));
|
|
}
|