So I'm trying to make use a tactile button to switch the effect of an led. I used two different loops for the effect but I don't know how to put the switch in the code and how to connect it to the circuit.
here is the code
#define button 2
#define led1 3
boolean modeState;
void setup() {
pinMode (led1, OUTPUT);
pinMode (button, INPUT_PULLUP);
}
void blink(){
digitalWrite (led1, HIGH);
delay (200);
digitalWrite (led1, LOW);
delay (200);
}
void fade(){
for (int a = 0; a <= 255; a+=50){
analogWrite (led1, a););
delay (100);
}
for (int a = 255; a >= 0; a -= 50){
analogWrite (led1, a);
delay (100);
}
}
void loop() {
int buttonState = digitalRead(button);
if (buttonState == LOW){
modeState = !modeState;
}
if (modeState == false){
blink();
}
else {
digitalWrite (led1, LOW);
}
}
Thank you
