I've encountered an annoying issue...
Basically, whenever the pushbutton is pressed the LED should display one of the 3 cases.
At the moment, it only displays case 0.
I need your help.
Here's my code, what's wrong with it?
int buttonPin = 2;
int led = 13;
int buttonState = 0;
void setup() {
pinMode(led, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
switch (buttonPin == HIGH) {
buttonState = random(3);
case 0:
digitalWrite(led, HIGH);
delay(150);
digitalWrite(led, LOW);
delay(500); //
digitalWrite(led, HIGH);
delay(150);
digitalWrite(led, LOW);
break;
case 1:
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(500); //
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
break;
case 2:
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(100); //
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
break;
}
}
else {
digitalWrite(led, LOW);
}
}
Thanks!
Much appreciated!