fbpx

Seven Segment Display

A seven-segment display is used to display digits from 0-9.Seven segment display widely used in digital clocks,weight machine, Ph meters etc. The common configuration has an array of eight LED’s arranged to display these digits.LEDs are assigned with alphabets from a to h and its identified by those alphabets. Seven LED’s a to g are used to display the numerals while eighth led h is used to display the dot/decimal.

Hardware Required

  • Resistor
  • Raspberry pi
  • Jumper wires
  • Seven segment display.
  • Breadboard

Circuit

Code

  • Create a new text file “ssd.py” by typing the following” nano ssd.py “
  • Now type the following code 
 import RPi.GPIO as GPIO
import time
DISPLAY=[0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67]   //hex code for digits0-9
GPIO.setmode(GPIO.BCM)                               //BCM is broadcom which specifies the actual pin number considered by broadcom chip 
GPIO.setwarnings(False)                                     //Ignore warnings
GPIO.setup(12 ,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)       
GPIO.setup(4  ,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24  ,GPIO.OUT)
GPIO.setup(25,GPIO.OUT)
 
def PORT(pin):                             //function to assign logic to pin
 
if(pin&0x01==0x01):
GPIO.output (12, 1)
else:
GPIO.output (12, 0)
 
if(pin&0x02==0x02):
GPIO.output (16, 1)
else:
GPIO.output (16, 0)
if(pin&0x04==0x04):
GPIO.output (20, 1)
else:
GPIO.output (20, 0)
 
if(pin&0x08==0x08):
GPIO.output (4, 1)
else:
GPIO.output (4, 0)
 
if(pin&0x10==0x10):
GPIO.output (23, 1)
else
GPIO.output (23, 0)
 
if(pin&0x20==0x20):
GPIO.output (24, 1)
else:
GPIO.output (24, 0)
 
if(pin&0x40==0x40):
GPIO.output (25, 1)
else:
GPIO.output (25, 0)
 while1:                                 
for x in range(10):;
pin=DISPLAY[x]
PORT(pin);
time.sleep(2) 

Leave a Reply

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