//integer variables labeling led groups and what pins they are on
int pinLeds1 = D6;
int pinLeds2 = D5;
int pinLeds3 = D4;
int pinLed4 = D3;
//integer variable labeling what pin the button is on
int buttonPin = D7;
//button will randomize from 1 to 6
int buttonState;
long ran;
int timeDelay = 2000;
//open setup
void setup ()
{
//start the serial monitor
Serial.begin(115200);
//set up led pins as output
pinMode (pinLeds1, OUTPUT);
pinMode (pinLeds2, OUTPUT);
pinMode (pinLeds3, OUTPUT);
pinMode (pinLed4, OUTPUT);
//set up button pin as input
pinMode (buttonPin, INPUT_PULLUP);
// random number generator
randomSeed(esp_random());
// Print dice start in serial monitor
Serial.println("");
Serial.println("Dice Start");
}
//close setup
//open loop
void loop()
{
//read the button
int buttonState = digitalRead(buttonPin);
//checks to see what the last and current state of the button is
if (buttonState == LOW)
{
//start with all of the LED's in the off position
digitalWrite (pinLeds1, LOW);
digitalWrite (pinLeds2, LOW);
digitalWrite (pinLeds3, LOW);
digitalWrite (pinLed4, LOW);
//when button is pressed, pick a random number from 1 to 6
ran = random(1, 7);
//when number 1 is chosen, turn on the group 4 leds and wait
if (ran == 1)
{
Serial.println("1");
digitalWrite (pinLed4, HIGH);
delay (timeDelay);
}
//when number 2 is chosen, turn on the group 1 leds and wait
if (ran == 2)
{
Serial.println("2");
digitalWrite (pinLeds1, HIGH);
delay (timeDelay);
}
//when number 3 is chosen, turn on the groups 3 and 4 leds and wait
if (ran == 3)
{
Serial.println("3");
digitalWrite (pinLeds3, HIGH);
digitalWrite (pinLed4, HIGH);
delay (timeDelay);
}
//when number 4 is chosen, turn on the groups 1 and 3 leds and wait
if (ran == 4)
{
Serial.println("4");
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds3, HIGH);
delay (timeDelay);
}
//when number 5 is chosen, turn on the groups 1, 3, and 4 leds and wait
if (ran == 5)
{
Serial.println("5");
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds3, HIGH);
digitalWrite (pinLed4, HIGH);
delay (timeDelay);
}
//when number 6 is chosen, turn on the groups 1, 2, and 3 leds and wait
if (ran == 6)
{
Serial.println("6");
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds2, HIGH);
digitalWrite (pinLeds3, HIGH);
}
}
}