#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_err.h"
#include <stdbool.h>
#define LIGHT_DURATION_MS 3000
esp_err_t lightOn(gpio_num_t pin)
{
return gpio_set_level(pin, 1);
}
esp_err_t lightOff(gpio_num_t pin)
{
return gpio_set_level(pin, 0);
}
static void setLight(gpio_num_t pin, bool on)
{
if (on) {
ESP_ERROR_CHECK(lightOn(pin));
} else {
ESP_ERROR_CHECK(lightOff(pin));
}
}
static void setLights(bool red, bool orange, bool green)
{
setLight(GPIO_NUM_7, red);
setLight(GPIO_NUM_8, orange);
setLight(GPIO_NUM_9, green);
}
void app_main() {
gpio_config_t led_config = {
.pin_bit_mask = (1ULL << GPIO_NUM_7) |
(1ULL << GPIO_NUM_8) |
(1ULL << GPIO_NUM_9),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
ESP_ERROR_CHECK(gpio_config(&led_config));
while (1) {
setLights(true, false, false); // Rood
vTaskDelay(pdMS_TO_TICKS(LIGHT_DURATION_MS));
setLights(false, false, true);
vTaskDelay(pdMS_TO_TICKS(LIGHT_DURATION_MS));
setLights(false, true, false);
vTaskDelay(pdMS_TO_TICKS(LIGHT_DURATION_MS));
}
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1