const int S1=14, S2=27, ledPin = 12; // 16 corresponds to GPIO16
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup(){
ledcSetup(ledChannel, freq, resolution);
pinMode(S1, INPUT);
pinMode(S2, INPUT);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
}
void loop(){
main:
if( digitalRead(S1)==1 & digitalRead(S2)==0){
goto on1;
}
else{
goto main;
}
goto main;
on1:
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
ledcWrite(ledChannel, dutyCycle);
if(digitalRead(S2)==1& digitalRead(S1)==0){
ledcWrite(0,0);
goto main;
}
delay(10);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
ledcWrite(ledChannel, dutyCycle);
if(digitalRead(S2)==1& digitalRead(S1)==0){
ledcWrite(0,0);
goto main;
}
delay(10);
}
goto on1;
}