#include <stdio.h>
#include "pico/stdlib.h"
#define led_verm 15
#define led_amar 14
#define led_verd 13
bool timer_0_callback(repeating_timer_t *rt);
int main() {
stdio_init_all();
gpio_init(led_verm);
gpio_set_dir(led_verm, GPIO_OUT);
gpio_init(led_amar);
gpio_set_dir(led_amar, GPIO_OUT);
gpio_init(led_verd);
gpio_set_dir(led_verd, GPIO_OUT);
gpio_put(led_verm, 0);
gpio_put(led_amar, 0);
gpio_put(led_verd, 0);
repeating_timer_t timer;
add_repeating_timer_ms(1000, timer_0_callback, NULL, &timer);
while (true) { tight_loop_contents(); }
}
bool timer_0_callback(repeating_timer_t *rt) {
static int t = 0; // contador interno do temporizador
t++;
// ----- 1) Piscar vermelho 3 vezes -----
if (t <= 6) {
if (t == 1)
gpio_put(led_verm, 1); // liga
if (t == 2)
gpio_put(led_verm, 0); // desliga
if (t == 3)
gpio_put(led_verm, 1); // liga
if (t == 4)
gpio_put(led_verm, 0); // desliga
if (t == 5)
gpio_put(led_verm, 1); // liga
if (t == 6)
gpio_put(led_verm, 0); // desliga
return true;
}
// ----- 2) Verde → Amarelo → Vermelho -----
gpio_put(led_verm, 0);
gpio_put(led_amar, 0);
gpio_put(led_verd, 0);
if (t == 7)
gpio_put(led_verd, 1);
if (t == 8)
gpio_put(led_verd, 0);
if (t == 9)
gpio_put(led_amar, 1);
if (t == 10)
gpio_put(led_amar, 0);
if (t == 11)
gpio_put(led_verm, 1);
if (t == 12)
gpio_put(led_verm, 0);
// ----- 3) Piscar verde 2 vezes -----
if (t == 13)
gpio_put(led_verd, 1);
if (t == 14)
gpio_put(led_verd, 0);
if (t == 15)
gpio_put(led_verd, 1);
if (t == 16)
gpio_put(led_verd, 0);
// ----- Reinicia -----
if (t >= 16)
t = 0;
return true;
}