使用的pin为D23 。
#include <stdio.h>
#include <inttypes.h>
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#define BLINK_GPIO GPIO_NUM_23
void hello_task(void *pvParameter)
{
int b =145;
int *a= &b;
while(1)
{
printf("Hello world %d!\n",*a);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
void blinky(void *pvParameter)
{
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while(1) {
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
/**
*
*
https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/hw-reference/esp32/get-started-devkitc.html
*
*
*/
void app_main(void) {
printf("Hello world!\n");
int a = 123;
xTaskCreate(&hello_task, "hello_task", 2048, &a, 5, NULL);
xTaskCreate(&blinky, "blinky", 2048, &a, 5, NULL);
}
参考 :
https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/hw-reference/esp32/get-started-devkitc.html
https://github.com/DiegoPaezA/ESP32-freeRTOS/blob/master/Task_FreeRTOS/main.c
https://lastminuteengineers.com/esp32-pinout-reference/