Simple Dice Using LED Matrix and Arduino Uno R3

Components Required

  • Arduino Uno r3
  • 8×8 LED matrix module
  • 5mm push button
  • 830 points breadboard
  • Wires
  • Arduino cable

Overview

This dice project using Arduino Uno r3 is the most basic dice project that is perfect to start now. This uses the basic concept of interfacing a led matrix with an Arduino and generating a random number using a push button.

Every time the user presses the push button, the led matrix displays a random number from 1 to 6. The connection is really simple as shown in the image. Upload the code and you are ready with your first electronics dice.

Circuit Diagram

Code

include “LedControl.h”

LedControl lc=LedControl(12,11,10,1);

unsigned long delaytime=500;
byte six[8]={B00000000,B11011011,B11011011,B00000000,B00000000,B11011011,B11011011,B00000000};
byte five[8]={B00000000,B01100110,B01100110,B00011000,B00011000,B01100110,B01100110,B00000000};
byte four[8]={B00000000,B01100110,B01100110,B00000000,B00000000,B01100110,B01100110,B00000000};
byte three[8]={B11000000,B11000000,B00000000,B00011000,B00011000,B00000000,B00000011,B00000011};
byte two[8]={B00000000,B00000000,B00000000,B01100110,B01100110,B00000000,B00000000,B00000000};
byte one[8]={B00000000,B00000000,B00000000,B00011000,B00011000,B00000000,B00000000,B00000000};

void setup() {

lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
}

void one1() {

lc.setRow(0,0,one[0]);
lc.setRow(0,1,one[1]);
lc.setRow(0,2,one[2]);
lc.setRow(0,3,one[3]);
lc.setRow(0,4,one[4]);
lc.setRow(0,5,one[5]);
lc.setRow(0,6,one[6]);
lc.setRow(0,7,one[7]);

delay(delaytime);
}
void two2() {

lc.setRow(0,0,two[0]);
lc.setRow(0,1,two[1]);
lc.setRow(0,2,two[2]);
lc.setRow(0,3,two[3]);
lc.setRow(0,4,two[4]);
lc.setRow(0,5,two[5]);
lc.setRow(0,6,two[6]);
lc.setRow(0,7,two[7]);

delay(delaytime);
}
void three3() {

lc.setRow(0,0,three[0]);
lc.setRow(0,1,three[1]);
lc.setRow(0,2,three[2]);
lc.setRow(0,3,three[3]);
lc.setRow(0,4,three[4]);
lc.setRow(0,5,three[5]);
lc.setRow(0,6,three[6]);
lc.setRow(0,7,three[7]);

delay(delaytime);
}
void four4() {

lc.setRow(0,0,four[0]);
lc.setRow(0,1,four[1]);
lc.setRow(0,2,four[2]);
lc.setRow(0,3,four[3]);
lc.setRow(0,4,four[4]);
lc.setRow(0,5,four[5]);
lc.setRow(0,6,four[6]);
lc.setRow(0,7,four[7]);

delay(delaytime);
}
void five5() {

lc.setRow(0,0,five[0]);
lc.setRow(0,1,five[1]);
lc.setRow(0,2,five[2]);
lc.setRow(0,3,five[3]);
lc.setRow(0,4,five[4]);
lc.setRow(0,5,five[5]);
lc.setRow(0,6,five[6]);
lc.setRow(0,7,five[7]);

delay(delaytime);
}
void six6() {

lc.setRow(0,0,six[0]);
lc.setRow(0,1,six[1]);
lc.setRow(0,2,six[2]);
lc.setRow(0,3,six[3]);
lc.setRow(0,4,six[4]);
lc.setRow(0,5,six[5]);
lc.setRow(0,6,six[6]);
lc.setRow(0,7,six[7]);

delay(delaytime);
}

void loop() {
int x;
if(analogRead(A4)==1000)
{
x = random(1,6);
}
switch(x){
case 1 : one1();
break;
case 2 : two2();
break;
case 3 : three3();
break;
case 4 : four4();
break;
case 5 : five5();
break;
case 6 : six6();
break;}
}

Leave a Reply

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