#include <FreeRTOS.h>
#include <task.h>
#include <semphr.h>
#include <queue.h>
#include "pico/stdlib.h"
#include <stdio.h>
const int BTN_PIN_R = 28;
const int BTN_PIN_G = 26;
const int LED_PIN_R = 4;
const int LED_PIN_G = 6;
QueueHandle_t xQueueButId;
void led_1_task(void *p) {
gpio_init(LED_PIN_R);
gpio_set_dir(LED_PIN_R, GPIO_OUT);
int delay = 0;
while (true) {
if (xQueueReceive(xQueueButId, &delay, 0)) {
printf("%d\n", delay);
}
if (delay > 0) {
gpio_put(LED_PIN_R, 1);
vTaskDelay(pdMS_TO_TICKS(delay));
gpio_put(LED_PIN_R, 0);
vTaskDelay(pdMS_TO_TICKS(delay));
}
}
}
void btn_1_task(void *p) {
gpio_init(BTN_PIN_R);
gpio_set_dir(BTN_PIN_R, GPIO_IN);
gpio_pull_up(BTN_PIN_R);
int delay = 0;
while (true) {
if (!gpio_get(BTN_PIN_R)) {
while (!gpio_get(BTN_PIN_R)) {
vTaskDelay(pdMS_TO_TICKS(1));
}
if (delay < 1000) {
delay += 100;
} else {
delay = 100;
}
printf("delay btn %d \n", delay);
xQueueSend(xQueueButId, &delay, 0);
}
}
}
int main() {
stdio_init_all();
printf("Start RTOS \n");
xQueueButId = xQueueCreate(32, sizeof(int));
xTaskCreate(led_1_task, "LED_Task 1", 256, NULL, 1, NULL);
xTaskCreate(btn_1_task, "BTN_Task 1", 256, NULL, 1, NULL);
vTaskStartScheduler();
while (true)
;
}Loading
pi-pico-w
pi-pico-w