#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
//declaring the function
void printbin8(uint8_t valu);
//calling the definition function
void dec();
//creating an array to declare the pins
int LEDs[8] = {40,39,38,37,36,35,0,45};
//defining the gpio pins
void app_main() {
dec();
//initializing the unsigned integer ‘count’ to 0
uint8_t count = 0;
while (1) {
// calls the printbin8 function
printbin8(count);
//counts up by one
count++;
vTaskDelay(2000 / portTICK_PERIOD_MS); // Delay for 500 milliseconds
}
}
/*function name- printbin8
*description - prints out the binary value in a for loop
*return type- returns nothing
*parameters-valu
*/
//defining the function
void printbin8(uint8_t valu) {
printf("The value of %i in binary is: 0b", valu); // Use %u for uint8_t
for (int i = 7;i >= 0;i--) {
//prints the current value
printf("%i",(valu >> i) & 1);
//It turns the leds on sequentially
gpio_set_level(LEDs[i],(valu >> i) & 1);
}
printf("\n");
}
void dec(){
for(uint8_t w=0; w<7; w++){
//setting the directions
gpio_set_direction(LEDs[w], GPIO_MODE_OUTPUT);
}
}