32

33 for (int i = 10; i 》= 0; i--) {

34 printf(“Restarting in %d seconds.。。\n”, i);

35 vTaskDelay(1000 / portTICK_PERIOD_MS);

36 }

37 printf(“Restarting now.\n”);

38 fflush(stdout);

39 esp_restart();//重启选项

40 }

参考example下的GPIO例子,简单修改如下:

复制代码

1 * Hello World Example

2

3 This example code is in the Public Domain (or CC0 licensed, at your option.)

4

5 Unless required by applicable law or agreed to in writing, this

6 software is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR

7 CONDITIONS OF ANY KIND, either express or implied.

8 */

9 #include 《stdio.h》

10 #include “freertos/FreeRTOS.h”

11 #include “freertos/task.h”

12 #include “esp_system.h”

13 #include “esp_spi_flash.h”

14

15

16 #include 《string.h》

17 #include 《stdlib.h》

18 #include “freertos/FreeRTOS.h”

19 #include “freertos/task.h”

20 #include “freertos/queue.h”

21 #include “driver/gpio.h”

22

23 #define GPIO_OUTPUT_IO_LED 2

24 #define GPIO_OUTPUT_PIN_SEL ((1《《GPIO_OUTPUT_IO_LED) )

25 int i=0;

26 void app_main()

27 {

28

29 //初始化GPIO引脚,直接复制自GPIO例子

30 gpio_config_t io_conf;

31 //disable interrupt

32 io_conf.intr_type = GPIO_PIN_INTR_DISABLE;

33 //set as output mode

34 io_conf.mode = GPIO_MODE_OUTPUT;

35 //bit mask of the pins that you want to set,e.g.GPIO2

36 io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;

37 //disable pull-down mode