Button and lights – Arduino

Today  started working whit Arduino (again), but this time I have a good excuse to use it so I hope this will be integrated with future work, around march this year I did a couple of tutorials using Arduino, but I did not document them, now I am going to do it as an exercise for my memory and also to tidy up mi knowledge on this matter, it is worth to mention that recently I started to study C# and my goal is to be able to connect both VR and Arduino through Unity.

This first example is just a simple circuit that allows me to change the order for the lights to turn on, so I am using a push button to do this, if the button is not pressed (LOW), the lights will be turned on in an specific order, otherwise, if the button is pressed (HIGH) the order will change (this is an exercise form the Arduino starter kit)

This is the code:

//this is te variable that is going to store the two values for the bush button
int switchState=0;
void setup() {
  //we use the pinMode function to set the pins to be either for input or for output
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(2,INPUT);

}

void loop() {
  //we loop to check if the button is pressed
  switchState = digitalRead(2);
  //if the button is not pressed then the lights get turned on in this sequence
  if(switchState == LOW){
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
  delay(250); //wait for a quarter of a second
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  delay(250); //wait for a quarter of a second
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  delay(250); //wait for a quarter of a second
  //if the button is pressed then the lights are turned on in this sequence
} else {
  
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  delay(250); //wait for a quarter of a second
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  delay(250); //wait for a quarter of a second
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
  delay(250); //wait for a quarter of a second
  }
}

This is the circuit being tested