#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "rom/gpio.h"
// define os nomes dos endereços dos registradores
#define GPIO_ENABLE_REG 0x3FF44020
#define GPIO_OUT_REG 0x3FF44004
#define GPIO_IN1_REG 0x3FF44040
// --- Definição dos LEDs (saídas) ---
#define LED1 0
#define bt0 13
//cria um vetor com os valores em hexadecimal de 0 a F
uint32_t display[16] = {
0xE60020, //0
0x820000, //1
0xCC0020, //2
0xCA0020, //3
0xAA0000, //4
0x6A0020, //5
0x6E0020, //6
0xC20000, //7
0xEE0020, //8
0xEA0020, //9
0xEE0000, //a
0x2E0020, //b
0x640020, //c
0x8E0020, //d
0x6C0020, //e
0x6C0000};//f
//0b111011100000000000100000
void config_hardware();
void config_saida();
void app_main() {
bool bt0_value;
config_hardware();
config_saida();
//habilita os pinos
REG_WRITE(GPIO_ENABLE_REG, 0b111011100000000000100001);
while(true){
bt0_value = gpio_get_level(bt0);
if(bt0_value == 0){
for(int i = 9; i>-1; i--){
REG_WRITE(GPIO_OUT_REG, display[i]);
REG_WRITE(GPIO_OUT_W1TS_REG, (1 << LED1));
vTaskDelay(500 / portTICK_PERIOD_MS);
}
for(int i =0; i<5; i++){
REG_WRITE(GPIO_OUT_W1TC_REG, (1 << LED1));
vTaskDelay(500 / portTICK_PERIOD_MS);
REG_WRITE(GPIO_OUT_W1TS_REG, (1 << LED1));
vTaskDelay(500 / portTICK_PERIOD_MS);
}
REG_WRITE(GPIO_OUT_REG, display[9]);
REG_WRITE(GPIO_OUT_W1TC_REG, (1 << LED1));
}
}
}
void config_hardware() {
gpio_pad_select_gpio(bt0);
gpio_set_direction(bt0, GPIO_MODE_INPUT);
gpio_set_pull_mode(bt0, GPIO_PULLUP_ONLY);
}
void config_saida() {
gpio_set_level(LED1,0);
}
CHAVE
Pot1
BTN1
BTN0
LEDS
DISPLAY