LED Dice using Arduino Uno

990.00

LED Dice:

  • Components: Arduino board, 7 LEDs, pushbutton, resistors, wires.
  • Description: When you press the button, the Arduino generates a random number (1 to 6) and displays it on the LED array to simulate a dice roll.
Add to Wishlist
Add to Wishlist
SKU: DT-64287 Category:
Ask for More Info

Description

LED Dice

A simple project (with an intermediate code level) to make an 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

 

Bread board                                    x 1

× 1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Schematics

Image

Code

Code for LED Dice

Arduino

/*This is a simple project to make LED Dice by DishanTech BD.*/


//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]);
}
}

Reviews

There are no reviews yet.

Be the first to review “LED Dice using Arduino Uno”

Your email address will not be published. Required fields are marked *