/**
   Simon Game for Arduino with Score display

   Copyright (C) 2022, Uri Shaked

   Released under the MIT License.
*/

#include "pitches.h"

/* Constants - define pin numbers for LEDs,
   buttons and speaker, and also the game tones: */
const uint8_t Traffic_lights[] = {2,3,4,5,6,7,8,9,10, 11, 12,13};
uint8_t TL[4][3];
int sens = -1;
int index_start = 2;
/**
   Set up the Arduino board and initialize Serial communication
*/
void setup() {
  Serial.begin(9600);
  for (int i=0;i<4;i++){
  for (int j=0;j<3;j++){
    TL[i][j]=Traffic_lights[i*3+j];
  }
}
  for (byte i = 0; i < 3; i++) {
    pinMode(Traffic_lights[i], OUTPUT);
    // pinMode(buttonPins[i], INPUT_PULLUP);
  }
  randomSeed(analogRead(A3));
}
void traffic_light_cycle(const uint8_t Traffic_light_Spot[],int index_start,int sens){
  int i = index_start;
  if (sens < 0){
    digitalWrite(Traffic_light_Spot[i-2], LOW);
    digitalWrite(Traffic_light_Spot[i], HIGH);
    delay(1500);
    digitalWrite(Traffic_light_Spot[i],LOW);
    digitalWrite(Traffic_light_Spot[i-1],HIGH);
    delay(300);
    digitalWrite(Traffic_light_Spot[i-1],LOW);
    digitalWrite(Traffic_light_Spot[i-2],HIGH);
    delay(1500);
  }
  else{
    digitalWrite(Traffic_light_Spot[i+2], LOW);
    digitalWrite(Traffic_light_Spot[i], HIGH);
    delay(1500);
    digitalWrite(Traffic_light_Spot[i],LOW);
    digitalWrite(Traffic_light_Spot[i+1],HIGH);
    delay(300);
    digitalWrite(Traffic_light_Spot[i+1],LOW);
    digitalWrite(Traffic_light_Spot[i+2],HIGH);
    delay(1500);
  }

}
/**
   The main game loop
*/
void loop() {
  sens = -sens;
  index_start = 2-index_start;
  traffic_light_cycle(,index_start,sens);
}