Skip to content

Instantly share code, notes, and snippets.

@kcranley1
Last active November 22, 2015 12:12
Show Gist options
  • Save kcranley1/b586e73654d96a4971ce to your computer and use it in GitHub Desktop.
Save kcranley1/b586e73654d96a4971ce to your computer and use it in GitHub Desktop.
S&S's version for a common ANODE 7-segment display driven by Raspberry Pi
# S&S's version for a common ANODE 7-segment display driven by Raspberry Pi
# code modified, tweaked and tailored from code by bertwert
# on RPi forum thread topic 91796
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# GPIO ports for the 7seg pins
segments = (11,4,23,8,7,10,18,25)
# 7seg_segment_pins (14,16,13,3,5,11,15,7) + 670R inline
for segment in segments:
GPIO.setup(segment, GPIO.OUT)
GPIO.output(segment, 1)
# GPIO ports for the digit 0-3 pins
digits = (22,27,17,24)
# 7seg_digit_pins (1,2,6,8) digits 0-3 respectively
for digit in digits:
GPIO.setup(digit, GPIO.OUT)
GPIO.output(digit, 0)
# note these digits are all inverted compared with the common cathode display:
num = {' ':(1,1,1,1,1,1,1),
'0':(0,0,0,0,0,0,1),
'1':(1,0,0,1,1,1,1),
'2':(0,0,1,0,0,1,0),
'3':(0,0,0,0,1,1,0),
'4':(1,0,0,1,1,0,0),
'5':(0,1,0,0,1,0,0),
'6':(0,1,0,0,0,0,0),
'7':(0,0,0,1,1,1,1),
'8':(0,0,0,0,0,0,0),
'9':(0,0,0,0,1,0,0)}
try:
while True:
n = time.ctime()[11:13]+time.ctime()[14:16]
s = n.rjust(4)
for digit in range(4):
if (int(time.ctime()[18:19])%2 == 0) and (digit == 1):
GPIO.output(25, 0)
else:
GPIO.output(25, 1)
for loop in range(0,7):
GPIO.output(segments[loop], num[s[digit]][loop])
GPIO.output(digits[digit], 1)
time.sleep(0.005)
GPIO.output(digits[digit], 0)
finally:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment