Created
April 28, 2026 20:51
-
-
Save je4npw/40a96e71927e4459dd525092e772b2dc 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.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 int tempo_delay_ms = 500; | |
| // 500 ms ligado + 500 ms desligado = 1 Hz | |
| void vTaskBotao(void *pvParameters) | |
| { | |
| while (1) { | |
| int btn_pressionado = gpio_get_level(BTN_PIN) == 0; | |
| if (btn_pressionado) { | |
| // 2 Hz -> ciclo completo de 500 ms | |
| // 250 ms ligado + 250 ms desligado | |
| tempo_delay_ms = 250; | |
| } else { | |
| // 1 Hz -> ciclo completo de 1000 ms | |
| // 500 ms ligado + 500 ms desligado | |
| tempo_delay_ms = 500; | |
| } | |
| vTaskDelay(pdMS_TO_TICKS(50)); | |
| } | |
| } | |
| void vTaskPiscaLed(void *pvParameters) | |
| { | |
| while (1) { | |
| gpio_set_level(LED_PIN, 1); | |
| vTaskDelay(pdMS_TO_TICKS(tempo_delay_ms)); | |
| gpio_set_level(LED_PIN, 0); | |
| vTaskDelay(pdMS_TO_TICKS(tempo_delay_ms)); | |
| } | |
| } | |
| 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( | |
| vTaskPiscaLed, | |
| "Task_Pisca_LED", | |
| 2048, | |
| NULL, | |
| 5, | |
| NULL | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment