// Define the pins
const int dataPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // Pins D2 to D9 for data bits
const int enablePin = 10; // Pin D10 for the enable signal

void setup() {
  // Set data pins as outputs
  for (int i = 0; i < 8; i++) {
    pinMode(dataPins[i], OUTPUT);
  }
  // Set enable pin as output
  pinMode(enablePin, OUTPUT);
}

void loop() {
  // Count up
  for (int i = 0; i < 256; i++) {
    displayBinary(i);
    delay(1000); // Delay for visibility
  }

  // Count down
  for (int i = 255; i >= 0; i--) {
    displayBinary(i);
    delay(1000);
  }
}

void displayBinary(int value) {
  // Enable the output
  digitalWrite(enablePin, HIGH);

  // Set data pins based on the binary value
  for (int i = 0; i < 8; i++) {
    digitalWrite(dataPins[i], (value >> i) & 1);
  }

  // Disable the output
  digitalWrite(enablePin, LOW);
}