// Forum: https://forum.arduino.cc/t/problem-with-arduino-nano-analog-pins/1237926
// This Wokwi project: https://wokwi.com/projects/392905000289997825
// The sketch has added fading and bouncing at the ends.
//

/*
  check leds
*/
  
#define TRAFFIC_LIGHT_SPEED 100

const int led_pins_list[6] = {11,10,9,6,5,3};
// the setup function runs once when you press reset or power the board


// Variables for fading and bouncing
int f1 = -1;
int f2 = -1;
int index = 0;
int direction = 1;


void setup()
{
  Serial.begin(9600);
  // initialize digital pin LED_BUILTIN as an output.
  for(int i = 0;i < 6;i++)
  {
    pinMode(led_pins_list[i], OUTPUT);
  }
}

// the loop function runs over and over again forever
void loop()
{
  analogWrite(led_pins_list[index],255);    // turn the LED on
  delay(TRAFFIC_LIGHT_SPEED);               // wait some time
  analogWrite(led_pins_list[index],40);     // dim the led
  if(f1 >= 0)
    analogWrite(led_pins_list[f1],2);       // dim the led even more
  if(f2 >= 0)
    analogWrite(led_pins_list[f2],0);       // finally turn off the led
  delay(TRAFFIC_LIGHT_SPEED);               // wait some time
  f2 = f1;  
  f1 = index;
  index += direction;                       // next led
  if(index == 0 or index == 5)
    direction = -direction;
}