#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 10 vezes -----
if (t <= 20) {
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
if (t == 7)
gpio_put(led_verm, 1); // liga
if (t == 8)
gpio_put(led_verm, 0); // desliga
if (t == 9)
gpio_put(led_verm, 1); // liga
if (t == 10)
gpio_put(led_verm, 0); // desliga
if (t == 11)
gpio_put(led_verm, 1); // liga
if (t == 12)
gpio_put(led_verm, 0); // desliga
if (t == 13)
gpio_put(led_verm, 1); // liga
if (t == 14)
gpio_put(led_verm, 0); // desliga
if (t == 15)
gpio_put(led_verm, 1); // liga
if (t == 16)
gpio_put(led_verm, 0); // desliga
if (t == 17)
gpio_put(led_verm, 1); // liga
if (t == 18)
gpio_put(led_verm, 0); // desliga
if (t == 19)
gpio_put(led_verm, 1); // liga
if (t == 20)
gpio_put(led_verm, 0); // desliga
return true;
}
// ----- 2) Piscar Amarelo 5 vezes -----
gpio_put(led_verm, 0);
gpio_put(led_amar, 0);
gpio_put(led_verd, 0);
if (t == 21)
gpio_put(led_amar, 1); // liga
if (t == 22)
gpio_put(led_amar, 0); // desliga
if (t == 23)
gpio_put(led_amar, 1); // liga
if (t == 24)
gpio_put(led_amar, 0); // desliga
if (t == 25)
gpio_put(led_amar, 1); // liga
if (t == 26)
gpio_put(led_amar, 0); // desliga
if (t == 27)
gpio_put(led_amar, 1); // liga
if (t == 28)
gpio_put(led_amar, 0); // desliga
if (t == 29)
gpio_put(led_amar, 1); // liga
if (t == 30)
gpio_put(led_amar, 0); // desliga
// ----- 3) Piscar verde 7 vezes -----
if (t == 31)
gpio_put(led_verd, 1); // liga
if (t == 32)
gpio_put(led_verd, 0); // desliga
if (t == 33)
gpio_put(led_verd, 1); // liga
if (t == 34)
gpio_put(led_verd, 0); // desliga
if (t == 35)
gpio_put(led_verd, 1); // liga
if (t == 36)
gpio_put(led_verd, 0); // desliga
if (t == 37)
gpio_put(led_verd, 1); // liga
if (t == 38)
gpio_put(led_verd, 0); // desliga
if (t == 39)
gpio_put(led_verd, 1); // liga
if (t == 40)
gpio_put(led_verd, 0); // desliga
if (t == 41)
gpio_put(led_verd, 1); // liga
if (t == 42)
gpio_put(led_verd, 0); // desliga
if (t == 43)
gpio_put(led_verd, 1); // liga
if (t == 44)
gpio_put(led_verd, 0); // desliga
// ----- Reinicia -----
if (t >= 44)
t = 0;
return true;
}