#include <stdio.h>
#include "pico/stdlib.h"
#define A 10
#define B 11
#define C 13
#define D 14
#define E 15
#define F 9
#define G 8
#define CH1 18
uint8_t segmentos[7] = {A, B, C, D, E, F, G};
bool display_valor[4][7] = {
{1,1,1,0,1,1,1},
{1,1,1,1,0,1,1},
{1,0,1,1,1,1,1},
{1,0,1,1,0,1,1}
};
int main() {
stdio_init_all();
for (int i = 0; i < 7; i++) {
gpio_init(segmentos[i]);
gpio_set_dir(segmentos[i], GPIO_OUT);
}
gpio_init(CH1);
gpio_set_dir(CH1, GPIO_IN);
gpio_pull_up(CH1);
int numero = 0;
while (true) {
bool sentido = !gpio_get(CH1);
for (int s = 0; s < 7; s++) {
gpio_put(segmentos[s], display_valor[numero][s]);
}
sleep_ms(1000);
if (sentido == 0) {
// Contagem crescente
numero++;
if (numero > 3) numero = 0;
} else {
// Contagem decrescente
numero--;
if (numero < 0) numero = 3;
}
}
}