const int ledPins[] = {13,9,4,1};
void setup()
{
for (int i = 0; i < 4; i++)
{
pinMode(ledPins[i], OUTPUT);
}
}
void loop()
{
for (int num = 0; num <= 15; num++)
{
displayBinary(num);
delay(1000);
displayBinary(~num & 0x0F);
delay(1000);
}
delay(2000);
}
void displayBinary(int num)
{
for (int i = 0; i < 4; i++)
{
digitalWrite(ledPins[i], (num >> i) & 1);
}
}