#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
// defining LEDs of segments
#define A_SEG 0
/*int bits[] = {0x01, 0x4f, 0X12, 0x06, 0x4c,
0x24, 0x20, 0x0f, 0x0, 0x0c,
0x08, 0x60, 0x31, 0x42, 0x30,
0x38};*/
int bits[] = {0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001,
0b0010010, 0b10, 0b1111000, 0b0, 0b0011000,
0b0001000, 0b11, 0b1000110, 0b0100001,
0b0000110, 0b0001110};
int c = 0;
int bit_mng;
int main() {
stdio_init_all();
const uint8_t pulsador = 28; // or use #define
gpio_init(pulsador);
gpio_set_dir(pulsador, GPIO_IN);
// This is to avoid the need to define
// each LED one by one
for (int gpio = A_SEG; gpio < A_SEG + 7; gpio++) {
gpio_init(gpio);
gpio_set_dir(gpio, GPIO_OUT);
gpio_set_outover(gpio, GPIO_OVERRIDE_NORMAL);
}
//int bit_mng = bits[c]
while (true) {
//printf("Hello, Wokwi!\n");
// sleep_ms(250);
// for (int cnt=0; cnt<=15; cnt++) {
// since it's pull down, no need to negate
// the gpio
if (gpio_get(pulsador)) {
if (c == 15) {
c = 0;
} else {
c++;
}
gpio_clr_mask(bit_mng);
}
bit_mng = bits[c];
//bit_mng = bits[c]; // << A_SEG;
// this is needed, if persay the first
// segment starts at GP1 instead of GP0
// so we shift to the left that
// everything is in order
gpio_set_mask(bit_mng);
sleep_ms(300);
}
}