esp-idf-template/components/heartbeat/heartbeat.c

30 lines
902 B
C
Raw Normal View History

2017-02-21 06:43:44 +00:00
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define HEARTBEAT_GPIO GPIO_NUM_5
#define HEARTBEAT_PERIOD_MS 1000
2017-02-21 06:43:44 +00:00
void heartbeat_task(void *pvParameter)
{
/* Configure the IOMUX register for pad HEARTBEAT_GPIO (some pads are
muxed to GPIO on reset already, but some default to other
functions and need to be switched to GPIO. Consult the
Technical Reference for a list of pads and their default
functions.)
*/
gpio_pad_select_gpio(HEARTBEAT_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(HEARTBEAT_GPIO, GPIO_MODE_OUTPUT);
while(1) {
/* Heartbeat off (output low) */
gpio_set_level(HEARTBEAT_GPIO, 0);
vTaskDelay(HEARTBEAT_PERIOD_MS / portTICK_PERIOD_MS);
/* Heartbeat on (output high) */
gpio_set_level(HEARTBEAT_GPIO, 1);
vTaskDelay(HEARTBEAT_PERIOD_MS / portTICK_PERIOD_MS);
}
}