#!/usr/bin/env python # File mm5491_demo.py # http://www.bristolwatch.com/index.htm # by Lewis Loflin lewis@sullivan-county.com # http://www.bristolwatch.com/ele2/rpi_MM5451.htm # access to GPIO must be through root # for driving common anode displays # brightness control eliminates need for resistors # Vcc 4.75 - 13V # 7-segment common anode display connected bits 1-8 # 8 LEDs bits 9-16 common anodes # access to GPIO must be through root import RPi.GPIO as GPIO import time CLK =12 dataBit = 7 GPIO.setup(CLK, GPIO.OUT) # P1 GPIO.setup(dataBit, GPIO.OUT) # P7 # Setup IO GPIO.output(dataBit, 0) GPIO.output(CLK, 0) def pulseCLK(): GPIO.output(CLK, 1) GPIO.output(CLK, 0) return # LSB out first! def ssrWriteLSB(value): for x in range(0,8): temp = value & 0x01 if temp == 0x01: GPIO.output(dataBit, 1) # data bit HIGH else: GPIO.output(dataBit, 0) # data bit LOW pulseCLK() value = value >> 0x01 # shift left return # MSB out first! def ssrWriteMSB(value): for x in range(0,8): temp = value & 0x80 if temp == 0x80: GPIO.output(dataBit, 1) # data bit HIGH else: GPIO.output(dataBit, 0) # data bit LOW pulseCLK() value = value << 0x01 # shift left return def zeroWrite(num1): GPIO.output(dataBit, 0) # data bit HIGH for x in range(0, num1): pulseCLK() return ''' GPIO.output(dataBit, 1) # data bit HIGH pulseCLK() ssrWrite(0b11000110) zeroWrite() ''' # 7-segment display code array segCode =[ 0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01100111 ] for myCount in range(0, 256): # start bit GPIO.output(dataBit, 1) pulseCLK() # the "+ 0x80" turns on DP ssrWriteLSB(segCode[myCount % 10]) # MOD myCount ssrWriteMSB(myCount) # 8 LEDs binary count 0-255 zeroWrite(21) # pad remaining bits with 0s time.sleep(.2) print "Good by!" exit