Now I have built fongtoy module ftguzuntypi and tested OK the function
ftguzuntypi.TestGuzuntyPi4digit7segmentLedModule(spiChannelNumber = 0, spiChipEnableNumber = 1)
# ftmain v1.1 tlfong01 2013may21
# *** Program Description ***
ProgramTitle = "FongToy v1.0 tlfong01 2013may20 "
# *** System Imports ***
import sys
import time
import smbus
import pdb
import spidev
import wiringpi
import wiringpi2
import RPIO as GPIO
from RPIO import PWM
from enum import Enum
from subprocess import call
# *** Fongtoy imports ***
import ftio
import ftprint
import ftspi
import ftiox
import fteeprom
import ftguzuntypi
# *** Main function ***
ftprint.StartProgram(ProgramTitle)
# *** Testing SPI loop back ***
# print "Testing SPI loop back, ..."
# ftspi.TestSpiLoopBack(spiChannelNumber = 0, spiChipEnableNumber = 1, testDataByte = 0x55, testCount = 1000, testTime = 0.001)
# ftspi.TestSpiLoopBack(spiChannelNumber = 0, spiChipEnableNumber = 0, testDataByte = 0x55, testCount = 600000, testTime = 0.001)
# *** Testing EEPROM
# fteeprom.TestWriteReadEepormDataByte(spiChannelNumber = 0, spiChipEnableNumber = 1, startAddress = 0x0410, testDataByte = 0x55)
# *** Testing MCP23S17 blink LED ***
# print "Testing MCP23S17 blink LED, ..."
# ftiox.TestMcp23s17BlinkLed(spiChannelNumber = 0, spiChipEnableNumber = 0, spiChipSubAddress = 0)
ftguzuntypi.TestGuzuntyPi4digit7segmentLedModule(spiChannelNumber = 0, spiChipEnableNumber = 1)
ftprint.StopProgram()
#.END
# ftguzuntypi.py v1.1 tlfong01 2013may21
import time
import spidev
from subprocess import call
import ftspi
# *****************************************************************************
# Function -
# Description -
# Sample call -
# ftguzuntypi.TestGuzuntyPi4digit7segmentLedModule(spiChannelNumber = 0, spiChipEnableNumber = 1)
# Sample output -
# *** Start Program - FongToy v1.0 tlfong01 2013may20 ***
# Tue May 21 08:43:18 2013
# Hour digit 1 = 0
# Hour digit 2 = 8
# Minute digit 1 = 4
# Minute digit 2 = 3
# Second digit 1 = 1
# Second digit 2 = 8
# hourDoubleDigit 0 = 0
# hourDoubleDigit 1 = 8
# minuteDoubleDigit 0 = 4
# minuteDoubleDigit 1 = 3
# secondDoubleDigit 0 = 1
# secondDoubleDigit 1 = 8
# hour = 0 8
# minute = 4 3
# second = 1 8
# *** Stop Program ***
# *****************************************************************************
def SetRpiPin7GpClk0Frequency4688Hz():
returnCode = call(["gpio mode 7 clock"], shell = True)
returnCode = call("gpio clock 7 4688", shell=True)
def TestGuzuntyPi4digit7segmentLedModule(spiChannelNumber, spiChipEnableNumber):
spiChannel = spidev.SpiDev()
spiChannel.open(spiChannelNumber, spiChipEnableNumber)
SetRpiPin7GpClk0Frequency4688Hz()
# *** 7 segment patterns ***
#PatternDigit0 = ~0x3f
#PatternDigit1 = ~0x06
#PatternDigit2 = ~0x5b
#PatternDigit3 = ~0x4f
#PatternSpace = 0xff
#PatternAllOn = 0x00
PatternBigG = 0x3d
PatternSmallG = 0x6f
PatternSmallO = 0x5c
PatternSmallD = 0x5e
PatternDigit0 = 0x3f
PatternDigit1 = 0x06
PatternDigit2 = 0x5b
PatternDigit3 = 0x4f
PatternSpace = ~0xff
PatternAllOn = ~0x00
PatternBigG = 0x3d
PatternSmallG = 0x6f
PatternSmallO = 0x5c
PatternSmallD = 0x5e
PatternListAllOff = [PatternSpace, PatternSpace, PatternSpace, PatternSpace]
PatternListAllOn = [PatternAllOn, PatternAllOn, PatternAllOn, PatternAllOn]
PatternList0123 = [PatternDigit0, PatternDigit1, PatternDigit2, PatternDigit3]
PatternListGood = [PatternBigG, PatternSmallO, PatternSmallO, PatternSmallD]
# *** time digits ***
timeString = time.asctime(time.localtime(time.time()))
print timeString
print "Hour digit 1 = ", timeString[11:12]
print "Hour digit 2 = ", timeString[12:13]
print "Minute digit 1 = ", timeString[14:15]
print "Minute digit 2 = ", timeString[15:16]
print "Second digit 1 = ", timeString[17:18]
print "Second digit 2 = ", timeString[18:19]
hourDoubleDigit = [timeString[11:12], timeString[12:13]]
print "hourDoubleDigit 0 = ", hourDoubleDigit[0]
print "hourDoubleDigit 1 = ", hourDoubleDigit[1]
minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
print "minuteDoubleDigit 0 = ", minuteDoubleDigit[0]
print "minuteDoubleDigit 1 = ", minuteDoubleDigit[1]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]
print "secondDoubleDigit 0 = ", secondDoubleDigit[0]
print "secondDoubleDigit 1 = ", secondDoubleDigit[1]
timeHexDigit = [hourDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "hour = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]
timeHexDigit = [minuteDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "minute = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]
timeHexDigit = [secondDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "second = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]
# *** 4 digit 7-segment LED displays ***
# spiGuzuntyPi.xfer2(PatternListAllOff)
# time.sleep(1)
# spiGuzuntyPi.xfer2(PatternListAllOn)
# time.sleep(1)
# spiGuzuntyPi.xfer2(PatternList0123)
# time.sleep(2)
# spiGuzuntyPi.xfer2(PatternListGood)
# time.sleep(2)
ftspi.SpiWrite(spiChannel, PatternListAllOff)
time.sleep(1)
ftspi.SpiWrite(spiChannel, PatternListAllOn)
time.sleep(1)
ftspi.SpiWrite(spiChannel, PatternList0123)
time.sleep(2)
ftspi.SpiWrite(spiChannel, PatternListGood)
time.sleep(2)
# SevenSegmentPatternNumbers = [~0x3f, ~0x06, ~0x5b, ~0x4f, ~0x66, ~0x6d, ~0x7d, ~0x07, ~0x7f, ~0x6f]
SevenSegmentPatternNumbers = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f]
decimalPoint = 0
for i in range(2):
timeString = time.asctime(time.localtime(time.time()))
hourDoubleDigit = [timeString[11:12], timeString[12:13]]
minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]
minuteDigit0 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[0])]
minuteDigit1 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[1])]
secondDigit0 = SevenSegmentPatternNumbers[int(secondDoubleDigit[0])]
secondDigit1 = SevenSegmentPatternNumbers[int(secondDoubleDigit[1])]
if (decimalPoint == 0):
#minuteDigit1 &= ~0x80
minuteDigit1 |= 0x80
decimalPoint = 1
else:
decimalPoint = 0
minuteSecondQuadDigitList = [minuteDigit0, minuteDigit1, secondDigit0, secondDigit1]
ftspi.SpiWrite(spiChannel, minuteSecondQuadDigitList)
time.sleep(1)
def TestGuzuntyPiLedDriver00(spiChannel, channelNumber, chipEnableNumber):
SetRpiPin7GpClk0Frequency4688Hz()
spiGuzuntyPi = spidev.SpiDev()
spiGuzuntyPi.open(0, 1)
# *** 7 segment patterns ***
#PatternDigit0 = ~0x3f
#PatternDigit1 = ~0x06
#PatternDigit2 = ~0x5b
#PatternDigit3 = ~0x4f
#PatternSpace = 0xff
#PatternAllOn = 0x00
PatternBigG = 0x3d
PatternSmallG = 0x6f
PatternSmallO = 0x5c
PatternSmallD = 0x5e
PatternDigit0 = 0x3f
PatternDigit1 = 0x06
PatternDigit2 = 0x5b
PatternDigit3 = 0x4f
PatternSpace = ~0xff
PatternAllOn = ~0x00
PatternBigG = 0x3d
PatternSmallG = 0x6f
PatternSmallO = 0x5c
PatternSmallD = 0x5e
PatternListAllOff = [PatternSpace, PatternSpace, PatternSpace, PatternSpace]
PatternListAllOn = [PatternAllOn, PatternAllOn, PatternAllOn, PatternAllOn]
PatternList0123 = [PatternDigit0, PatternDigit1, PatternDigit2, PatternDigit3]
PatternListGood = [PatternBigG, PatternSmallO, PatternSmallO, PatternSmallD]
# *** time digits ***
timeString = time.asctime(time.localtime(time.time()))
print timeString
print "Hour digit 1 = ", timeString[11:12]
print "Hour digit 2 = ", timeString[12:13]
print "Minute digit 1 = ", timeString[14:15]
print "Minute digit 2 = ", timeString[15:16]
print "Second digit 1 = ", timeString[17:18]
print "Second digit 2 = ", timeString[18:19]
hourDoubleDigit = [timeString[11:12], timeString[12:13]]
print "hourDoubleDigit 0 = ", hourDoubleDigit[0]
print "hourDoubleDigit 1 = ", hourDoubleDigit[1]
minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
print "minuteDoubleDigit 0 = ", minuteDoubleDigit[0]
print "minuteDoubleDigit 1 = ", minuteDoubleDigit[1]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]
print "secondDoubleDigit 0 = ", secondDoubleDigit[0]
print "secondDoubleDigit 1 = ", secondDoubleDigit[1]
timeHexDigit = [hourDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "hour = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]
timeHexDigit = [minuteDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "minute = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]
timeHexDigit = [secondDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "second = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]
# *** 4 digit 7-segment LED displays ***
spiGuzuntyPi.xfer2(PatternListAllOff)
time.sleep(1)
spiGuzuntyPi.xfer2(PatternListAllOn)
time.sleep(1)
spiGuzuntyPi.xfer2(PatternList0123)
time.sleep(2)
spiGuzuntyPi.xfer2(PatternListGood)
time.sleep(2)
# SevenSegmentPatternNumbers = [~0x3f, ~0x06, ~0x5b, ~0x4f, ~0x66, ~0x6d, ~0x7d, ~0x07, ~0x7f, ~0x6f]
SevenSegmentPatternNumbers = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f]
decimalPoint = 0
for i in range(2):
timeString = time.asctime(time.localtime(time.time()))
hourDoubleDigit = [timeString[11:12], timeString[12:13]]
minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]
minuteDigit0 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[0])]
minuteDigit1 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[1])]
secondDigit0 = SevenSegmentPatternNumbers[int(secondDoubleDigit[0])]
secondDigit1 = SevenSegmentPatternNumbers[int(secondDoubleDigit[1])]
if (decimalPoint == 0):
#minuteDigit1 &= ~0x80
minuteDigit1 |= 0x80
decimalPoint = 1
else:
decimalPoint = 0
minuteSecondQuadDigitList = [minuteDigit0, minuteDigit1, secondDigit0, secondDigit1]
spiGuzuntyPi.xfer2(minuteSecondQuadDigitList)
time.sleep(1)
# .END
No comments:
Post a Comment