Week 4 Build - Dice Randomizer

This is an unsupported build, in that we are to explore and find out how to build this on our own. We did get support and we supported each other to help better understand how to do this build. This build is for a dice randomizer. Based on the programming and the “H” placement of the LEDs the Arduino will randomly generate numbers from 1 - 6 when you push the attached button on the breadboard. 

 

Unfortunately, I kept getting an “ERROR” message stating that the “five” was not declared in this scope. I don’t see how, as the rest of the numbers were declared. The schematic looks like the example I borrowed, but I don’t see where I went wrong. If you do, please let me know. 

 

Below is the drawing for this build. I made it up myself (So, I hope I did it right!) I used drawing from several different builds to make this. 

Video Information

As I said before, this didn’t work out like I had hoped and I wanted to explain what happened. I started here. From there I tried the code I had and this was my result, I am still working on it, so if I get it to work, I will let you know.

Code

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);

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){
six();
}
if (randNumber == 5){
five();
}
if (randNumber == 4){
four();
}
if (randNumber == 3){
three();
}
if (randNumber == 2){
two();
}
if (randNumber == 1){
one();
}
delay(4000);
clearAll();
state = 0;
}
}

void six()
{
digitalWrite(bottomLeft, HIGH);
digitalWrite(middleLeft, HIGH);
digitalWrite(upperLeft, HIGH);
digitalWrite(bottomRight, HIGH);
digitalWrite(middleRight, HIGH);
digitalWrite(upperRight, HIGH);
}

Dice Randomizer Data

Unfortunately. since I did not get the dice randomizer to work I do not have the data we were to generate. If I get it done, I will put the data here.  

Create Your Own Website With Webador