Skip to content

Instantly share code, notes, and snippets.

@je4npw
Created April 28, 2026 20:58
Show Gist options
  • Select an option

  • Save je4npw/19477016590de854983ac1632b4f5179 to your computer and use it in GitHub Desktop.

Select an option

Save je4npw/19477016590de854983ac1632b4f5179 to your computer and use it in GitHub Desktop.
Relatório de aula prática - Sistemas Embarcados - 7º semestre - Ciência da Computação - Aluno Jean Patrick Wilhvock
#include <stdio.h>
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED_PIN GPIO_NUM_2
#define BTN_PIN GPIO_NUM_4
volatile bool led_piscando = true;
void vTaskBotao(void *pvParameters)
{
int estado_anterior = 1;
while (1) {
int estado_atual = gpio_get_level(BTN_PIN);
// Detecta apenas o momento em que o botão é pressionado
// Com INPUT_PULLUP:
// solto = 1
// pressionado = 0
if (estado_anterior == 1 && estado_atual == 0) {
led_piscando = !led_piscando;
// debounce simples
vTaskDelay(pdMS_TO_TICKS(200));
}
estado_anterior = estado_atual;
vTaskDelay(pdMS_TO_TICKS(20));
}
}
void vTaskLed(void *pvParameters)
{
while (1) {
if (led_piscando) {
gpio_set_level(LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(500));
gpio_set_level(LED_PIN, 0);
vTaskDelay(pdMS_TO_TICKS(500));
} else {
gpio_set_level(LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(50));
}
}
}
void app_main(void)
{
gpio_reset_pin(LED_PIN);
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
gpio_reset_pin(BTN_PIN);
gpio_set_direction(BTN_PIN, GPIO_MODE_INPUT);
gpio_set_pull_mode(BTN_PIN, GPIO_PULLUP_ONLY);
xTaskCreate(
vTaskBotao,
"Task_Botao",
2048,
NULL,
5,
NULL
);
xTaskCreate(
vTaskLed,
"Task_LED",
2048,
NULL,
5,
NULL
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment