// https://wokwi.com/projects/422350080049242113
const int LEDpins[] = {2, 3, 4, 5}; //create an array of pin numbers
const int LEDpincount = sizeof LEDpins / sizeof *LEDpins; //calculate the size for use later
const int ON = HIGH; //defines the LED conditions in terms of output pin state
const int OFF = LOW;
int litestate[][LEDpincount] = //defines your states. Remember, if the number of pins changes, the number of columns will need changing
{
{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1},
{1, 1, 0, 0},
{1, 0, 1, 0},
{1, 0, 0, 1},
{0, 1, 1, 0},
{0, 1, 0, 1},
{0, 0, 1, 1},
{1, 1, 1, 0},
{1, 1, 1, 1}
};
const int states = sizeof litestate / sizeof *litestate; //calculate number of random states created
void setup() {
for (int ii = 0; ii < LEDpincount; ii++) { //loop through pin array
pinMode(LEDpins[ii], OUTPUT); //sets the mode of every LED pin
digitalWrite(LEDpins[ii], OFF); //not essential, but shuts off all LEDs to start with
}
}
void loop() {
int row = random(0, states);// since second limit is exclusive, we will never get states as a value, just states to states-1
for (int column = 0; column < LEDpincount; column++) {
digitalWrite(LEDpins[column],litestate[row][column]); //access the correct state for the row:pin desired
delay(166);
}
}