Utkarsh TiwariVidit Shah
Published © GPL3+

LED Dice

A simple project (with an intermediate code level) to make a LED Dice.

IntermediateShowcase (no instructions)1.5 hours17,259
LED Dice

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
3 mm LED: Red
3 mm LED: Red
×2
3 mm LED: Yellow
3 mm LED: Yellow
×2
3 mm LED: Green
3 mm LED: Green
×2
3 mm LED: Blue
×1
Jumper wires (generic)
Jumper wires (generic)
MALE TO MALE
×1
Resistor 221 ohm
Resistor 221 ohm
×7
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics

Image

Schematics

Fritzing File

Code

Code for LED Dice

Arduino
/*This is a simple project to make LED Dice.*/


//Defining LED Pins
int ledPins[7] = {2, 3, 4, 5, 6, 7, 8};
int dicePatterns[7][7] = {
{0, 0, 0, 0, 0, 0, 1}, // 1
{0, 0, 1, 1, 0, 0, 0}, // 2
{0, 0, 1, 1, 0, 0, 1}, // 3
{1, 0, 1, 1, 0, 1, 0}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 1, 1, 1, 1, 1, 0}, // 6
{0, 0, 0, 0, 0, 0, 0} // BLANK
};
int switchPin = 9;   //Defining button pin
int blank = 6;    
void setup()
{
for (int i = 0; i < 7; i++)
{
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
randomSeed(analogRead(0));
}
void loop()
{
  if (digitalRead(switchPin))
{
rollTheDice();
}
delay(100);
}
void rollTheDice()
{
int result = 0;
int lengthOfRoll = random(15, 25);
for (int i = 0; i < lengthOfRoll; i++)
{
result = random(0, 6); // result will be 0 to 5 not 1 to 6
show(result);
delay(50 + i * 10);
}
for (int j = 0; j < 3; j++)
{
show(blank);
delay(500);
show(result);
delay(500);
}
}
void show(int result)
{
for (int i = 0; i < 7; i++)
{
digitalWrite(ledPins[i], dicePatterns[result][i]);
}
}

Credits

Utkarsh Tiwari

Utkarsh Tiwari

10 projects • 40 followers
Trying to FIND myself! :P Interested in DIY's and coding!
Vidit Shah

Vidit Shah

10 projects • 39 followers
Programmer

Comments