#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void printbin8(uint8_t valu) { //This is a function which will print the value of an 8-bit unsigned integer when called. (JI)
printf("The value of %u in binary is: 0b", valu); // Use %u for uint8_t
for (int i = 7; i >= 0; i--) { //For-loop structure ensures we are printing from MSB to LSB and not exceeding 8 bits. (JI)
printf("%u", (valu >> i) & 1); //The value of 'valu' is right-shifted by 'i' from the for-loop. (JI)
}
//print the binary number here. Hint: you’ll need a for loop that reads the state of each of the 8 bits in the variable and prints it out in order (Most Significant Bit printed first (left most))
printf("\n");
}
void app_main() {
//initializing the unsigned integer ‘count’ to 0
uint8_t count = 0;
while (1) {
printbin8(count); //Function is called and repeated within a while-loop to ensure all 255 values are printed. Condition of 'count' ensures the value starts at 0 and then incremented. (JI)
count++; //Increments infinitely, but will repeat from 0 after reaching 255. (JI)
vTaskDelay(500 / portTICK_PERIOD_MS); // Delay for 500 milliseconds
}
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4