const int ledPin1 = 23;
const int ledPin2 = 22;
const int ledPin3 = 21;
const int freq = 5000;
const int ledChannel1 = 0;
const int ledChannel2 = 1;
const int ledChannel3 = 2;
const int resolution = 8;
int sw1 = 17;
int sw2 = 16;
int sw3 = 4;
int sw1State;
int sw2State;
int sw3State;
void setup() {
pinMode(sw1, INPUT);
pinMode(sw2, INPUT);
pinMode(sw3, INPUT);
ledcSetup(ledChannel1, freq, resolution);
ledcAttachPin(ledPin1, ledChannel1);
ledcSetup(ledChannel2, freq, resolution);
ledcAttachPin(ledPin2, ledChannel2);
ledcSetup(ledChannel3, freq, resolution);
ledcAttachPin(ledPin3, ledChannel3);
}
void loop() {
main:
sw1State = digitalRead(sw1);
if(sw1State == 0){
goto LTR;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
goto RTL;
}
goto main;
LTR:
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
//GREEN LED
for(int dutyCycle1 = 0; dutyCycle1 <= 255; dutyCycle1++){
ledcWrite(ledChannel1, dutyCycle1);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
delay(15);
}
for(int dutyCycle1 = 255; dutyCycle1 >= 0; dutyCycle1--){
ledcWrite(ledChannel1, dutyCycle1);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
delay(15);
}
//YELLOW LED
for(int dutyCycle2 = 0; dutyCycle2 <= 255; dutyCycle2++){
ledcWrite(ledChannel2, dutyCycle2);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
delay(15);
}
for(int dutyCycle2 = 255; dutyCycle2 >= 0; dutyCycle2--){
ledcWrite(ledChannel2, dutyCycle2);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
delay(15);
}
//RED LED
for(int dutyCycle3 = 0; dutyCycle3 <= 255; dutyCycle3++){
ledcWrite(ledChannel3, dutyCycle3);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
delay(15);
}
for(int dutyCycle3 = 255; dutyCycle3 >= 0; dutyCycle3--){
ledcWrite(ledChannel3, dutyCycle3);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
delay(15);
}
goto LTR;
RTL:
//RED LED
for(int dutyCycle3 = 0; dutyCycle3 <= 255; dutyCycle3++){
ledcWrite(ledChannel3, dutyCycle3);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
delay(15);
}
for(int dutyCycle3 = 255; dutyCycle3 >= 0; dutyCycle3--){
ledcWrite(ledChannel3, dutyCycle3);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
delay(15);
}
//YELLOW LED
for(int dutyCycle2 = 0; dutyCycle2 <= 255; dutyCycle2++){
ledcWrite(ledChannel2, dutyCycle2);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
delay(15);
}
for(int dutyCycle2 = 255; dutyCycle2 >= 0; dutyCycle2--){
ledcWrite(ledChannel2, dutyCycle2);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
delay(15);
}
//GREEN LED
for(int dutyCycle1 = 0; dutyCycle1 <= 255; dutyCycle1++){
ledcWrite(ledChannel1, dutyCycle1);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
delay(15);
}
for(int dutyCycle1 = 255; dutyCycle1 >= 0; dutyCycle1--){
ledcWrite(ledChannel1, dutyCycle1);
sw3State = digitalRead(sw3);
if(sw3State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto main;
}
sw1State = digitalRead(sw1);
if(sw1State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto LTR;
}
sw2State = digitalRead(sw2);
if(sw2State == 0){
ledcWrite(ledChannel1,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
goto RTL;
}
delay(15);
}
goto RTL;
}