This code will flag binary numbers up to 15 using the 4 LEDS connected to pins 10-13.
I wrote (vibe coded) this for my niece as she learns how to program an Arduino.
// We are using 4 LEDs connected to pins 10, 11, 12, and 13
// These 4 LEDs will show numbers in binary (from 0 to 15)
// This is an array.
// An array is a list of values stored under one name.
// Instead of writing four separate variables for four pins,
// we store them all in one list called "pins".
int pins[4] = {10, 11, 12, 13};
// pins[0] = 10
// pins[1] = 11
// pins[2] = 12
// pins[3] = 13
void setup() {
// setup() runs once when the Arduino turns on
// This loop goes through the array one item at a time
for (int i = 0; i < 4; i++) {
// Set each pin in the array to OUTPUT mode
// OUTPUT means the Arduino can turn the LED on or off
pinMode(pins[i], OUTPUT);
// Make sure the LED starts turned off
digitalWrite(pins[i], LOW);
}
}
void loop() {
// loop() runs over and over forever
// Count from 0 to 15
// 0–15 fits in 4 binary digits (0000 to 1111)
for (int number = 0; number < 16; number++) {
// Each LED represents one binary digit (bit)
// Bit 0 (1's place) → pin 10
if (number & 1) digitalWrite(pins[0], HIGH);
else digitalWrite(pins[0], LOW);
// Bit 1 (2's place) → pin 11
if (number & 2) digitalWrite(pins[1], HIGH);
else digitalWrite(pins[1], LOW);
// Bit 2 (4's place) → pin 12
if (number & 4) digitalWrite(pins[2], HIGH);
else digitalWrite(pins[2], LOW);
// Bit 3 (8's place) → pin 13
if (number & 8) digitalWrite(pins[3], HIGH);
else digitalWrite(pins[3], LOW);
// Wait half a second so we can see the LEDs change
delay(500);
}
}