Monday, 11 August 2014

7 Segment LED display Interfacing....


Here i will show you how to interface a 7 segment LED display with GR-Sakura (Arduino UNO compatible).

I have used LT543 Common Cathode display. Common Cathode LED’s (around Rs.10) are cheaper than Common Anode (around Rs.30).

 

Circuit Diagram:



The resistors i used are of 1k ohm. 3rd and 8th pin goes to ground.

CountDown from 9 to 0:

 


Code:

#include<rxduino.h>

byte seven[12][7] = { { 1,1,1,1,1,1,0 },  // = 0

                        { 0,1,1,0,0,0,0 },  // = 1

                      { 1,1,0,1,1,0,1 },  // = 2

                      { 1,1,1,1,0,0,1 },  // = 3

                      { 0,1,1,0,0,1,1 },  // = 4

                      { 1,0,1,1,0,1,1 },  // = 5

                      { 1,0,1,1,1,1,1 },  // = 6

                      { 1,1,1,0,0,0,0 },  // = 7

                      { 1,1,1,1,1,1,1 },  // = 8

                      { 1,1,1,1,0,1,1 },  // = 9

                     };

int pins[10]={30,31,32,33,7,6,5,4};

int main()

{               

  static int i=9,j;

  pinMode(30, OUTPUT);  

  pinMode(31, OUTPUT);

  pinMode(32, OUTPUT);

  pinMode(33, OUTPUT);

  pinMode(6, OUTPUT);

  pinMode(7, OUTPUT);

  pinMode(5, OUTPUT);

  pinMode(4, OUTPUT);
 
  delay(100);

  digitalWrite(4,1);

  while(1)

  {
                                  if(i<0)

                                  {
                                                  i=9;
                                  }
                                  else
                                  {
                                  for(j=0;j<7;j++)
                                  {
                                                  digitalWrite(pins[j],seven[i][j]);
                                  }
                                  delay(1000);
                                  i--;
                                  }
                  }
 

Interfacing with Keys to control the displaying count value:

 
Code:
 
#include<rxduino.h>
byte seven[20][7] = { { 1,1,1,1,1,1,0 },  // = 0
                      { 0,1,1,0,0,0,0 },  // = 1
                      { 1,1,0,1,1,0,1 },  // = 2
                      { 1,1,1,1,0,0,1 },  // = 3
                      { 0,1,1,0,0,1,1 },  // = 4
                      { 1,0,1,1,0,1,1 },  // = 5
                      { 1,0,1,1,1,1,1 },  // = 6
                      { 1,1,1,0,0,0,0 },  // = 7
                      { 1,1,1,1,1,1,1 },  // = 8
                      { 1,1,1,1,0,1,1 },  // = 9
                      { 1,1,1,0,1,1,1 },  // = A
                      { 1,1,1,1,1,1,1 },  // = B
                      { 1,0,0,1,1,1,0 },  // = C
                      { 1,1,1,1,1,1,0 },  // = D
                      { 1,0,0,1,1,1,1 },  // = E
                      { 1,0,0,0,1,1,1 }   // = F
                     };
int pins[10]={30,31,32,33,7,6,5,4};
 
int main()
{               
  static int i=-1,j;
  pinMode(30, OUTPUT);  
  pinMode(31, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(34, INPUT);   // input for key (increasing count)
  pinMode(35, INPUT);   // input for key (decreasing count)
  delay(100);
  digitalWrite(4,1);
  while(1)
  {
  if(digitalRead(34)==0)
  {
                  delay(200);        // Switch debouncing delay
                  if(digitalRead(34)==0)
                  {
                                  i++;
                                  if(i<16)                                                 
                                                {
                                                for(j=0;j<7;j++)
                                                {
                                                  delay(10);
                                                  digitalWrite(pins[j],seven[i][j]);
                                                }
                                                }
                                                else
                                                {
                                                                i=16;
                                                }
                  }
  }
   if(digitalRead(35)==0)
  {
                  delay(200);       // Switch debouncing delay
                  if(digitalRead(35)==0)
                  {
                                  if(i<0)
                                  {
                                                  i=0;
                                  }
                                  else
                                  {
                                  delay(10);
                                  for(j=0;j<7;j++)
                                  {
                                                  digitalWrite(pins[j],seven[i][j]);
                                  }
                                  i--;
                                  }
                  }
  }
  }
}
 
Video Demo:
 

No comments:

Post a Comment