#include <ezButton.h>
#define SWITCH_OFF 0
#define SWITCH_ON 1
ezButton button(2);
int switch_state = SWITCH_OFF;
const int VAL1 = 13;
const int VAL2 = 12;
const int VAL3 = 11;
const int VAL4 = 10;
const int VAL5 = 9;
const int VAL6 = 8;
int randomOutput;
void setup() {
Serial.begin(9600);
Serial.println("hello world.");
button.setDebounceTime(50);
pinMode(VAL1, OUTPUT);
pinMode(VAL2, OUTPUT);
pinMode(VAL3, OUTPUT);
pinMode(VAL4, OUTPUT);
pinMode(VAL5, OUTPUT);
pinMode(VAL6, OUTPUT);
}
void loop() {
button.loop();
if (button.isPressed()) switch_state = !switch_state;
if(switch_state == SWITCH_ON){
randomOutput = random(1, 7);
Serial.println(randomOutput);
switch (randomOutput) {
case 1:; {
digitalWrite(VAL1, HIGH);
}
break;
case 2:;
digitalWrite(VAL2, HIGH);
break;
case 3:;
digitalWrite(VAL3, HIGH);
break;
case 4:;
digitalWrite(VAL4, HIGH);
break;
case 5:;
digitalWrite(VAL5, HIGH);
break;
case 6:;
digitalWrite(VAL6, HIGH);
break;
}
delay(10);
digitalWrite(VAL1, LOW);
digitalWrite(VAL2, LOW);
digitalWrite(VAL3, LOW);
digitalWrite(VAL4, LOW);
digitalWrite(VAL5, LOW);
digitalWrite(VAL6, LOW);
switch_state = SWITCH_OFF;
} else {
switch_state = SWITCH_OFF;
}
}