// Define the pin assignments for the LEDs (assuming 8 LEDs connected to digital pins 2 to 9)
const int LED_pins[] = {2, 3, 4, 5, 6, 7, 8, 9};
// Variable to store the binary counter
unsigned int binary_counter = 0;
// Function to update LEDs based on binary counter
void update_LEDs() {
for (int i = 0; i < 8; i++) {
digitalWrite(LED_pins[i], (binary_counter & (1 << i)) >> i); // Set LED pin based on binary counter bit
}
}
void setup() {
// Initialize LED pins as output
for (int i = 0; i < 8; i++) {
pinMode(LED_pins[i], OUTPUT);
}
}
void loop() {
// Check if the binary counter has finished
if (binary_counter >= 256) {
// If the counter has finished, stop updating LEDs and exit the loop
return;
}
// Increment binary counter
binary_counter++;
// Update LEDs based on binary counter
update_LEDs();
// Delay for visualization (adjust as needed)
delay(500); // 500ms delay
}