forked from cathodecreations/raspberrypi-nixie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.py
105 lines (84 loc) · 2.13 KB
/
test2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python
import time
import RPi.GPIO as GPIO
from os import system
#Number of active Nixie Tubes
tubes = 6
# GPIO mapping
gpioData = 11
gpioSerialClock = 12
gpioParallelLoad = 8
#Send a pulse out the indicated strobe pin
def pulseGPIO(pin, direction=True, duration=0.001):
GPIO.output(pin, direction)
time.sleep(duration)
GPIO.output(pin, not(direction))
#Display digits on Nixies, bit by bit
def nixiebit(digit):
digit = int(max(0, min( int(digit), 15)))
for d in reversed(range (0, 4)):
GPIO.output(gpioData, bool(digit & (1 << d)) )
pulseGPIO(gpioSerialClock)
#Display String of digits
def nixieString(digitString):
for c in reversed(str(digitString)):
try:
nixiebit(int(c))
except ValueError:
nixiebit(15)
#Display number on Nixies
pulseGPIO(gpioParallelLoad)
#print 'Outputted to Nixies'
#Ask User for string to display
def userNixieString():
userInput = str(raw_input('Number to Display: '))
if userInput == 'exit':
return False
print tubes
nixienumber = userInput.rjust(tubes,'a')
print nixienumber
nixieString(nixienumber)
return True
#Sweep Counting nixie display
def sweepNixieString():
emptyString=' ' * (tubes - 1)
for digit in '1234567890':
for i in range (0,tubes):
x=emptyString[:i] + digit + emptyString[i:]
#print x
nixieString(x)
time.sleep(0.1)
for i in range (tubes-2, 0, -1):
x=emptyString[:i] + digit + emptyString[i:]
#print x
nixieString(x)
time.sleep(0.1)
return True
#init the GPIO pins
def nixieInit():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(gpioParallelLoad, GPIO.OUT)
GPIO.setup(gpioSerialClock, GPIO.OUT)
GPIO.setup(gpioData, GPIO.OUT)
GPIO.output(gpioParallelLoad, False)
GPIO.output(gpioSerialClock, False)
GPIO.output(gpioData, False)
if __name__=="__main__":
nixieInit()
#I just have a thing for clean screens...
system("clear")
keepLooping=True
print 'Hit Ctrl-C to Exit'
try:
while keepLooping:
#keepLooping=sweepNixieString()
keepLooping=userNixieString()
except:
# Do normal cleanup
print "Exception detected"
#Cleanup...
nixieString('a' * tubes)
print "Exiting..."
GPIO.cleanup()
#system("clear")