-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigitController.py
82 lines (65 loc) · 2.08 KB
/
digitController.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
import RPi.GPIO as gpio
from time import sleep
class Shifter():
#inputA=15
SHCPclock=6 #SHCP 8-stage shift register pin 11 clockpin
DSinput=26 #DS Serial Data input.
STCP=19 #STCP 8-bit storage register pin 12 register clock = latch
#clearPin=6 #latch MR pin 10
MR=5 #master reset SRCLR
def __init__(self):
self.setupBoard()
self.pause=0
def tick(self):
gpio.output(Shifter.SHCPclock,gpio.HIGH)
sleep(self.pause)
gpio.output(Shifter.SHCPclock,gpio.LOW)
sleep(self.pause)
def setValue(self,value):
print "Setting value", value
for i in range(24):
bitwise=0x800000>>i
bit=bitwise&value
if (bit==0):
gpio.output(Shifter.DSinput,gpio.LOW)
else:
gpio.output(Shifter.DSinput,gpio.HIGH)
Shifter.tick(self)
gpio.output(Shifter.STCP, gpio.HIGH)
def clear(self):
gpio.output(Shifter.MR,gpio.LOW)
Shifter.tick(self)
gpio.output(Shifter.MR,gpio.HIGH)
def setupBoard(self):
gpio.setmode(gpio.BCM)
#gpio.setup(Shifter.inputA,gpio.OUT)
#gpio.output(Shifter.inputA,gpio.HIGH)
gpio.setup(Shifter.DSinput,gpio.OUT)
gpio.output(Shifter.DSinput,gpio.LOW)
gpio.setup(Shifter.SHCPclock,gpio.OUT)
gpio.output(Shifter.SHCPclock,gpio.LOW)
gpio.setup(Shifter.STCP,gpio.OUT)
gpio.output(Shifter.STCP,gpio.LOW)
gpio.setup(Shifter.MR,gpio.OUT)
gpio.output(Shifter.MR,gpio.HIGH)
# def main():
# pause=0.5
# #gpio.setmode(gpio.BOARD)
# shifter=Shifter()
# running=True
# while running==True:
# try:
# #shifter.clear()
# #shifter.setValue(1)
# #sleep(1)
# shifter.clear()
# #shifter.setValue(0x0AAAAAA)
# sleep(pause)
# #shifter.clear()
# shifter.setValue(0x0555555)
# sleep(pause)
# except KeyboardInterrupt:
# running=False
#
# if __name__ == '__main__':
# main()