Dice with Arduino using seven segment display | amazing mj

In this tutorial we are going to interfacing Seven segment display with Arduino.
Seven segment is one type of led only witch is arranged in such manner like below.

To control the seven segment Led we need to power it with 5 volt with one resistor. seven segment led have 10 pin (5 pin each side) 
The middle one is anod or cathode. 
By this pin we consider the seven segment Led is common anod or common cathode.
I use common cathode type seven segment Led. 
The schematic is shown below.

Code of the seven segment display is given below
 <Start >
//this code is return by :Amazing mj
//for digital dice with seven segment display
//subcribe to amazing mj on youtube 
//if u have any question about this 
//project kindly drop comment in this video

#define a 2
#define b 3
#define c 4
#define d 5
#define e 6
#define f 7
#define g 8
#define h 9
#define ir 10  //in out pins
int val;       //variable



void setup() {
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(h, OUTPUT);
  pinMode(ir,INPUT);    // input - output pins
  Serial.begin(9600);    //for serial communication
}

void loop() {
  if (digitalRead(ir))
    while (digitalRead(ir));
    {
      val++;     //increament in "val"
    }
  Serial.println(val);
  switch ( val = random(1, 7))   //it gives random value in between 1 to 6
  {
    case 1: one();
      break;
    case 2: two();
      break;
    case 3: three();
      break;
    case 4: four();
      break;
    case 5: five();
      break;
    case 6: six();
      break;
  }
  delay(40);
}

void zero()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(g,LOW);
  digitalWrite(h,LOW);
}
void one()
{
  digitalWrite(a,LOW);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
  digitalWrite(h,LOW);
}
void two()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,LOW);
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(f,LOW);
  digitalWrite(g,HIGH);
  digitalWrite(h,LOW);
}
void three()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,HIGH);
  digitalWrite(h,LOW);
}
void four()
{
  digitalWrite(a,LOW);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
  digitalWrite(h,LOW);
}
void five()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,LOW);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
  digitalWrite(h,LOW);
}
void six()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,LOW);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
  digitalWrite(h,LOW);
}
void seven()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
  digitalWrite(h,LOW);
}
void eight()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
  digitalWrite(h,LOW);
}
void nine()
{
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  digitalWrite(e,LOW);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);
  digitalWrite(h,LOW);
}

<end>

Thank you for reading .
🔰🔰🔰🔰🔰🔰🔰🔰

Think Amazing
Be Amazing 


Comments