Arduino 7-Segment Display Dice

by 12mrman34 in Circuits > Arduino

304 Views, 1 Favorites, 0 Comments

Arduino 7-Segment Display Dice

setup.png

This is a 7-segment display dice I have made.

Supplies

1x 7-Segment Display

1x Arduino Uno

1x 220 ohm resistor

Supplies

arduino.jpg
7segment.png
resist.png

You need:

1x Arduino Uno R3

1x 7-Segment Display

1x 220 ohm resistor

Setup

setup.png

Setup your project as in the image. Once finished, you can continue to the next step.

Code

Copy this code:

int a= 11;
int b=12;
int c= 2;
int d =3;
int e = 6;
int f = 9;
int g = 10;
void setup()
{
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  chooseNum();
  
}
void two()
{
 digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
   digitalWrite(c,LOW);
  digitalWrite(d,HIGH);
   digitalWrite(e,HIGH);
  digitalWrite(f,LOW);
   digitalWrite(g,HIGH);
  delay(1000);
}
void three()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
   digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
   digitalWrite(e,LOW);
  digitalWrite(f,LOW);
   digitalWrite(g,HIGH);
  delay(1000);
}
void four()
{
  digitalWrite(a,LOW);
  digitalWrite(b,HIGH);
   digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
   digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
   digitalWrite(g,HIGH);
  delay(1000);
}
void five()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,LOW);
   digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
   digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
   digitalWrite(g,HIGH);
  delay(1000);
}
void six()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,LOW);
   digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
   digitalWrite(e,HIGH);
  digitalWrite(f,HIGH);
   digitalWrite(g,HIGH);
  delay(1000);
}
void seven()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
   digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
   digitalWrite(e,LOW);
  digitalWrite(f,LOW);
   digitalWrite(g,LOW);
  delay(1000);
}
void eight()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
   digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
   digitalWrite(e,HIGH);
  digitalWrite(f,HIGH);
   digitalWrite(g,HIGH);
  delay(1000);
}
void nine()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
   digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
   digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
   digitalWrite(g,HIGH);
  delay(1000);
}
  void one()
{
  digitalWrite(a,LOW);
  digitalWrite(b,HIGH);
   digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
   digitalWrite(e,LOW);
  digitalWrite(f,LOW);
   digitalWrite(g,LOW);
  delay(1000);
}
void chooseNum() {
  int randNum = random(1,7);
  Serial.begin(9600);
  Serial.println(randNum);
    
    if (randNum == 1) {
      one();
    }
    
    if (randNum == 2) {
      two();
    }
    
    if (randNum == 3) {
      three();
    }
    
    if (randNum == 4) {
      four();
    }
    
    if (randNum == 5) {
      five();
    }
    
    if (randNum == 6) {
      six();
    }
}
void loop() {
  chooseNum();
delay(1000);
   
 
}

How to Use

It will choose a new number every 1 second, so be quick!