blink.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Blink Example
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/task.h"
  10. #include "driver/gpio.h"
  11. #include "sdkconfig.h"
  12. /* Can use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
  13. or you can edit the following line and set a number here.
  14. */
  15. #define BLINK_GPIO CONFIG_BLINK_GPIO
  16. void app_main(void)
  17. {
  18. /* Configure the IOMUX register for pad BLINK_GPIO (some pads are
  19. muxed to GPIO on reset already, but some default to other
  20. functions and need to be switched to GPIO. Consult the
  21. Technical Reference for a list of pads and their default
  22. functions.)
  23. */
  24. gpio_reset_pin(BLINK_GPIO);
  25. /* Set the GPIO as a push/pull output */
  26. gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
  27. while(1) {
  28. /* Blink off (output low) */
  29. printf("Turning off the LED\n");
  30. gpio_set_level(BLINK_GPIO, 0);
  31. vTaskDelay(1000 / portTICK_PERIOD_MS);
  32. /* Blink on (output high) */
  33. printf("Turning on the LED\n");
  34. gpio_set_level(BLINK_GPIO, 1);
  35. vTaskDelay(1000 / portTICK_PERIOD_MS);
  36. }
  37. }