-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLED_display.py
102 lines (85 loc) · 2.17 KB
/
LED_display.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
import RPi.GPIO as GPIO
import time
delay = 0.0005
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
red1_pin = 11
green1_pin = 27
blue1_pin = 7
red2_pin = 8
green2_pin = 9
blue2_pin = 10
clock_pin = 17
a_pin = 22
b_pin = 23
c_pin = 24
latch_pin = 4
oe_pin = 18
GPIO.setup(red1_pin, GPIO.OUT)
GPIO.setup(green1_pin, GPIO.OUT)
GPIO.setup(blue1_pin, GPIO.OUT)
GPIO.setup(red2_pin, GPIO.OUT)
GPIO.setup(green2_pin, GPIO.OUT)
GPIO.setup(blue2_pin, GPIO.OUT)
GPIO.setup(clock_pin, GPIO.OUT)
GPIO.setup(a_pin, GPIO.OUT)
GPIO.setup(b_pin, GPIO.OUT)
GPIO.setup(c_pin, GPIO.OUT)
GPIO.setup(latch_pin, GPIO.OUT)
GPIO.setup(oe_pin, GPIO.OUT)
screen = [[0 for x in range(32)] for x in range(16)]
def clock():
GPIO.output(clock_pin, 1)
GPIO.output(clock_pin, 0)
def latch():
GPIO.output(latch_pin, 1)
GPIO.output(latch_pin, 0)
def bits_from_int(x):
a_bit = x & 1
b_bit = x & 2
c_bit = x & 4
return (a_bit, b_bit, c_bit)
def set_row(row):
#time.sleep(delay)
a_bit, b_bit, c_bit = bits_from_int(row)
GPIO.output(a_pin, a_bit)
GPIO.output(b_pin, b_bit)
GPIO.output(c_pin, c_bit)
#time.sleep(delay)
def set_color_top(color):
#time.sleep(delay)
red, green, blue = bits_from_int(color)
GPIO.output(red1_pin, red)
GPIO.output(green1_pin, green)
GPIO.output(blue1_pin, blue)
#time.sleep(delay)
def set_color_bottom(color):
#time.sleep(delay)
red, green, blue = bits_from_int(color)
GPIO.output(red2_pin, red)
GPIO.output(green2_pin, green)
GPIO.output(blue2_pin, blue)
#time.sleep(delay)
def refresh():
for row in range(8):
GPIO.output(oe_pin, 1)
set_color_top(0)
set_row(row)
#time.sleep(delay)
for col in range(32):
set_color_top(screen[row][col])
set_color_bottom(screen[row+8][col])
clock()
#GPIO.output(oe_pin, 0)
latch()
GPIO.output(oe_pin, 0)
time.sleep(delay)
def fill_rectangle(x1, y1, x2, y2, color):
for x in range(x1, x2):
for y in range(y1, y2):
screen[y][x] = color
def set_pixel(x, y, color):
screen[y][x] = color
def main() :
while True:
refresh()