#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
//Defining GPIO pins. (JI)
#define redLED 4
#define greenLED 5
#define blueLED 6
#define yellowLED 7
//Defining a constant, which is the number of elements in the 'leds' array. (JI)
#define NUM_LEDS 4
int leds[NUM_LEDS] = {redLED, greenLED, blueLED, yellowLED}; //Declaring an array with four elements, which represents each LED. (JI)
void app_main() {
//Initializing LEDs as outputs. (JI)
for (int i = 0; i < NUM_LEDS; i++) {
gpio_set_direction(leds[i], GPIO_MODE_OUTPUT);
}
while (1) { //While loop runs endlessly, turning each LED on in sequential order for one second, and then turning the LED off before moving onto the next LED. (JI)
// Turn on each LED sequentially
for (int i = 0; i < NUM_LEDS; i++) {
gpio_set_level(leds[i], 1); //Runs through an index to turn the LEDs on one at a time. (JI)
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_set_level(leds[i], 0); //Runs through an index to turn the LEDs off one at a time. (JI)
}
}
}Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1