移位寄存器Nixie时钟不显示时间

时间:2016-01-08 05:49:30

标签: raspberry-pi clock shift-register

我是Python新手,主要做硬件。我试图用移位寄存器和Raspberry PI 2创建一个Nixie时钟基座。我发现一个类似的项目是作者包含的示例代码,这里http://www.smbaker.com/raspberry-pi-nixie-tube-clock-prototype

硬件已设置并运行但是我在网上找到的测试代码中存在阻止Pi显示时间的内容。代码作为测试脚本,它将循环显示时间。正如我所说,我是Pi和Python的新手,我相信我遇到的障碍就是代码的结尾。数字在模式序列中显示数字0.1.2.4.8但从不显示时间。我已经包含了以下代码。

import RPi.GPIO as GPIO
import time
import datetime

PIN_DATA = 23
PIN_LATCH = 24
PIN_CLK = 25

班尼克西:     def init (self,pin_data,pin_latch,pin_clk,digits):         self.pin_data = pin_data         self.pin_latch = pin_latch         self.pin_clk = pin_clk         self.digits = digits

    GPIO.setmode(GPIO.BCM)

    # Setup the GPIO pins as outputs
    GPIO.setup(self.pin_data, GPIO.OUT)
    GPIO.setup(self.pin_latch, GPIO.OUT)
    GPIO.setup(self.pin_clk, GPIO.OUT)

    # Set the initial state of our GPIO pins to 0
    GPIO.output(self.pin_data, False)
    GPIO.output(self.pin_latch, False)
    GPIO.output(self.pin_clk, False)

def delay(self):
    # We'll use a 10ms delay for our clock
    time.sleep(0.010)

def transfer_latch(self):
    # Trigger the latch pin from 0->1. This causes the value that we've
    # been shifting into the register to be copied to the output.
    GPIO.output(self.pin_latch, True)
    self.delay()
    GPIO.output(self.pin_latch, False)
    self.delay()

def tick_clock(self):
    # Tick the clock pin. This will cause the register to shift its
    # internal value left one position and the copy the state of the DATA
    # pin into the lowest bit.
    GPIO.output(self.pin_clk, True)
    self.delay()
    GPIO.output(self.pin_clk, False)
    self.delay()

def shift_bit(self, value):
    # Shift one bit into the register.
    GPIO.output(self.pin_data, value)
    self.tick_clock()

def shift_digit(self, value):
    # Shift a 4-bit BCD-encoded value into the register, MSB-first.
    self.shift_bit(value&0x08)
    value = value << 1
    self.shift_bit(value&0x08)
    value = value << 1
    self.shift_bit(value&0x08)
    value = value << 1
    self.shift_bit(value&0x08)

def set_value(self, value):
    # Shift a decimal value into the register

    str = "%0*d" % (self.digits, value)

    for digit in str:
        self.shift_digit(int(digit))
        value = value * 10

    self.transfer_latch()

def main():     尝试:         nixie = Nixie(PIN_DATA,PIN_LATCH,PIN_CLK,4)

    # Uncomment for a simple test pattern
    #nixie.set_value(1234)

    # Repeatedly get the current time of day and display it on the tubes.
    # (the time retrieved will be in UTC; you'll want to adjust for your
    # time zone)
    while True:
        dt = datetime.datetime.now()
        nixie.set_value(dt.hour*100 + dt.minute)

finally:
    # Cleanup GPIO on exit. Otherwise, you'll get a warning next time toy
    # configure the pins.
    GPIO.cleanup()

如果名称 ==“主要”:     main()的

0 个答案:

没有答案