int LEDSTATE1 = LOW;
int LEDSTATE2 = LOW;
int LEDSTATE3 = LOW;
const int LED_PIN_R = 3;
const int LED_PIN_G = 4;
const int LED_PIN_B = 5;
const int BUTTON_PIN = 7;
long RAND;
int lastButtonState;
int currentButtonState;
const int DEBOUNCE_DELAY = 50;
int lastFlickerableState = LOW;
unsigned long lastDebounceTime = 0;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN_R, OUTPUT);
pinMode(LED_PIN_G, OUTPUT);
pinMode(LED_PIN_B, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
currentButtonState = digitalRead(BUTTON_PIN);
if (currentButtonState != lastFlickerableState){
lastDebounceTime = millis();
lastFlickerableState = currentButtonState;
}
if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
if (lastButtonState == HIGH && currentButtonState == LOW){
Serial.println(RAND);
RAND = random(1,4);
}
if (RAND == 1) {
LEDSTATE1 = HIGH;
}else{
LEDSTATE1 = LOW;
}
if (RAND == 2) {
LEDSTATE2 = HIGH;
}else{
LEDSTATE2 = LOW;
}
if (RAND == 3) {
LEDSTATE3 = HIGH;
}else{
LEDSTATE3 = LOW;
}
digitalWrite(LED_PIN_R, LEDSTATE1);
digitalWrite(LED_PIN_G, LEDSTATE2);
digitalWrite(LED_PIN_B, LEDSTATE3);
lastButtonState = currentButtonState;
}
}