void setup()
{
// set pins 2 through 9 as output
for (int i = 2; i <= 9; i++)
{
pinMode(i, OUTPUT); // initialize pins as outputs
}
Serial.begin(9600);
}
long i = 0;
void loop()
{
// iterate over the pins
// turn the LED on from lowest to the highest
for (int a = 2; a <= 9; a++)
{
byte bitValue = bitRead(i, a - 2); // read the bit at position a - 2 from i
Serial.print(bitValue);
digitalWrite(a, bitValue); // turn the LED on or off based on the bit value
}
Serial.println(); // print a new line for clarity
i++; // increment i
if (i == 256) // reset i when it reaches 256
{
i = 0;
}
delay(100); // wait for 100 ms
}