// This Wokwi project: https://wokwi.com/projects/391359639460020225
// Just a small framework for two crossing streets with traffic lights
// Public Domain
//
// I'm still thinking what the best way is to write the code.
//   With a library ? With a class ? With a Finite State Machine ?
//   With multitasking ?
//
// Order of leds:
//   0: Main Street going right
//   1: Main Street going left
//   2: Chestnut Road going down
//   3: Chestnut Road going up
//
//   0: green
//   1: yellow
//   2: red

int leds[4][3] =
{
  { 2, 3, 4},
  { 5, 6, 7},
  { 8, 9, 10},
  { 11, 12, 13},
};

void setup() 
{
  for(int i=0; i<4; i++)
    for(int j=0; j<3; j++)
      pinMode(leds[i][j],OUTPUT);

  // Turn on all leds to indicate the start of the sketch.
  for(int i=0; i<4; i++)
    for(int j=0; j<3; j++)
      digitalWrite(leds[i][j],HIGH);
  delay(1000);
  for(int i=0; i<4; i++)
    for(int j=0; j<3; j++)
      digitalWrite(leds[i][j],LOW);
  delay(1000);


  // Blink all leds, to show that they work
  for(int i=0; i<4; i++)
  {
    for(int j=0; j<3; j++)
    {
      digitalWrite(leds[i][j],HIGH);
      delay(400);
      digitalWrite(leds[i][j],LOW);
    }
  }

}

void loop() 
{
  // For now, there is no code for the traffic lights.
  // As an indication that this sketch does not work,
  // blink all the yellow leds.

  for(int i=0; i<4; i++)
    digitalWrite(leds[i][1],HIGH);
  delay(600);
  for(int i=0; i<4; i++)
    digitalWrite(leds[i][1],LOW);
  delay(800);
}
Main Street
Chestnut Road
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------