//Pin to to turn dice on & off
int button = 2;
//LED for DICE
int bottomLeft = 3;
int middleLeft = 4;
int upperLeft = 5;
int middle = 6;
int bottomRight = 7;
int middleRight = 8;
int upperRight = 9;
int state = 0;
long randNumber;
//Initial setup
void setup(){
pinMode(bottomLeft, OUTPUT);
pinMode(middleLeft, OUTPUT);
pinMode(upperLeft, OUTPUT);
pinMode(middle, OUTPUT);
pinMode(bottomRight, OUTPUT);
pinMode(middleRight, OUTPUT);
pinMode(upperRight, OUTPUT);
pinMode(button, INPUT_PULLUP);
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop(){
//Read our button if high then run dice
if (!digitalRead(button) == HIGH && state == 0){
state = 1;
randNumber = random(1, 7);
delay(100);
Serial.println(randNumber);
if (randNumber == 6){
ledOn(1,1,1,0,1,1,1);
//six();
}
if (randNumber == 5){
ledOn(1,0,1,1,1,1,1);
//five();
}
if (randNumber == 4){
ledOn(1,0,1,0,1,0,1);
//four();
}
if (randNumber == 3){
ledOn(0,0,1,1,1,0,0);
//three();
}
if (randNumber == 2){
ledOn(0,0,1,0,1,0,0);
//two();
}
if (randNumber == 1){
ledOn(0,0,0,1,0,0,0);
//one();
}
delay(5000);
ledOn(0,0,0,0,0,0,0);
//clearAll();
state = 0;
}
}
void ledOn(int L1, int L2, int L3, int L4, int L5, int L6, int L7){
digitalWrite(bottomLeft, L1);//
digitalWrite(middleLeft, L2);//
digitalWrite(upperLeft, L3);//-
digitalWrite(middle, L4);//
digitalWrite(bottomRight, L5);//-
digitalWrite(middleRight, L6);
digitalWrite(upperRight, L7);//
}