#include <stdio.h>
#include <pico/stdlib.h>
// Definição dos pinos
#define LED_PIN_VD 13 // LED Verde
#define LED_PIN_VM 12 // LED Vermelho
#define LED_PIN_AZ 11 // LED Azul
#define BUTTON_PIN_A 5 // Botão A
#define BUTTON_PIN_B 6 // Botão B
int main() {
// Inicializa os LEDs como saída
gpio_init(LED_PIN_VM);
gpio_set_dir(LED_PIN_VM, GPIO_OUT);
gpio_init(LED_PIN_VD);
gpio_set_dir(LED_PIN_VD, GPIO_OUT);
gpio_init(LED_PIN_AZ);
gpio_set_dir(LED_PIN_AZ, GPIO_OUT);
// Inicializa os botões como entrada com resistor de pull-down
gpio_init(BUTTON_PIN_A);
gpio_set_dir(BUTTON_PIN_A, GPIO_IN);
gpio_pull_down(BUTTON_PIN_A); // Ativa o resistor de pull-down
gpio_init(BUTTON_PIN_B);
gpio_set_dir(BUTTON_PIN_B, GPIO_IN);
gpio_pull_down(BUTTON_PIN_B); // Ativa o resistor de pull-down
while (true) {
// Verifica o estado dos botões (ativo em nível baixo com pull-down)
if (gpio_get(BUTTON_PIN_A)) {
// Botão A pressionado, acende o LED Azul
gpio_put(LED_PIN_AZ, 1);
gpio_put(LED_PIN_VM, 0);
gpio_put(LED_PIN_VD, 0);
sleep_ms(100); // Atraso de 100 milissegundos
} else if (gpio_get(BUTTON_PIN_B)) {
// Botão B pressionado, acende o LED Vermelho
gpio_put(LED_PIN_AZ, 0);
gpio_put(LED_PIN_VM, 1);
gpio_put(LED_PIN_VD, 0);
sleep_ms(100); // Atraso de 100 milissegundos
} else {
// Nenhum botão pressionado, acende o LED Verde
gpio_put(LED_PIN_AZ, 0);
gpio_put(LED_PIN_VM, 0);
gpio_put(LED_PIN_VD, 1);
}
}
return 0; // O programa nunca alcança esta linha
}