/**
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 byte Traffic_lights[] = {2,3,4,7,6,5,8,9,10, 11, 12,13};
byte TL[4][3];
byte sens = -1;
byte index_start = 0;
/**
Set up the Arduino board and initialize Serial communication
*/
void setup() {
Serial.begin(9600);
for (byte i=0;i<4;i++){
for (byte 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(byte Traffic_light_Spot[],int index_start,int sens,int time){
int i = index_start;
digitalWrite(Traffic_light_Spot[i], LOW);
digitalWrite(Traffic_light_Spot[i+sens*1], HIGH);
delay(300);
digitalWrite(Traffic_light_Spot[i+sens*1],LOW);
digitalWrite(Traffic_light_Spot[i+sens*2],HIGH);
delay(time);
digitalWrite(Traffic_light_Spot[i+sens*2],LOW);
}
/**
The main game loop
*/
void Set(int i){
traffic_light_cycle(TL[i],index_start,-sens,1500);
// delay(1500);
// traffic_light_cycle(TL[i],i,2-index_start,sens,3000);
}
void loop() {
for(int i=0;i<4;i++){
Set(i);
}
}