-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnokia7seg_test.py
179 lines (129 loc) · 3.31 KB
/
nokia7seg_test.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Emulating a TM1637 quad 7-segment display module on a Nokia 5110 display
# WeMos D1 Mini -- Nokia 5110 PCD8544 LCD
# D3 (GPIO0) ----- 0 RST
# D4 (GPIO2) ----- 1 CE
# D8 (GPIO15) ---- 2 DC
# D7 (GPIO13) ---- 3 Din
# D5 (GPIO14) ---- 4 Clk
# 3V3 ------------ 5 Vcc
# D6 (GPIO12) ---- 6 BL
# G -------------- 7 Gnd
from machine import Pin, SPI
import time
import pcd8544
import nokia7seg
spi = SPI(1)
spi.init(baudrate=8000000, polarity=0, phase=0)
cs = Pin(2)
dc = Pin(15)
rst = Pin(0)
# backlight on
bl = Pin(12, Pin.OUT, value=1)
lcd = pcd8544.PCD8544(spi, cs, dc, rst)
display = nokia7seg.Nokia7Seg(lcd)
# all LEDS on "8.8.:8.8."
display.write([255, 255, 255, 255])
display.colon(True)
# all LEDS off
display.write([0, 0, 0, 0])
# display "3.145"
display.write([207, 6, 102, 109])
# display "0123"
display.write([63, 6, 91, 79])
display.write(bytearray([63, 6, 91, 79]))
# display "4567"
display.write([102, 109, 125, 7])
# set middle two segments to "12", "4127"
display.write([6, 91], 1)
# set last segment to "9", "4129"
display.write([111], 3)
# walk through all possible LED combinations
for i in range(255):
display.write([i, i | 0x80, i, i])
# show "AbCd"
display.write([119, 124, 57, 94])
display.show('abcd')
# show "COOL"
display.write([0b00111001, 0b00111111, 0b00111111, 0b00111000])
display.show('cool')
# converts a digit 0-0x0f to a byte representing a single segment
# use write() to render the byte on a single segment
display.encode_digit(0)
# 63
display.encode_digit(8)
# 127
display.encode_digit(0x0f)
# 113
# 15 or 0x0f generates a segment that can output a F character
display.encode_digit(15)
# 113
display.encode_digit(0x0f)
# 113
# used to convert a 1-4 length string to an array of segments
display.encode_string(' 1')
# bytearray(b'\x00\x00\x00\x06')
display.encode_string('2 ')
# bytearray(b'[\x00\x00\x00')
display.encode_string('1234')
# bytearray(b'\x06[Of')
display.encode_string('-12-')
# bytearray(b'@\x06[@')
display.encode_string('cafe')
# bytearray(b'9wqy')
display.encode_string('CAFE')
# bytearray(b'9wqy')
display.encode_string('a')
# bytearray(b'w\x00\x00\x00')
display.encode_string('ab')
# bytearray(b'w|\x00\x00')
# used to convert a single character to a segment byte
display.encode_char('1')
# 6
display.encode_char('9')
# 111
display.encode_char('-')
# 64
display.encode_char('a')
# 119
display.encode_char('F')
# 113
# display "dEAd", "bEEF", "CAFE" and "bAbE"
display.hex(0xdead)
display.hex(0xbeef)
display.hex(0xcafe)
display.hex(0xbabe)
# show " FF" (hex right aligned)
display.hex(0xff)
# show " 1" (numbers right aligned)
display.number(1)
# show " 12"
display.number(12)
# show " 123"
display.number(123)
# show "9999" capped at 9999
display.number(20000)
# show " -1"
display.number(-1)
# show " -12"
display.number(-12)
# show "-123"
display.number(-123)
# show "-999" capped at -999
display.number(-1234)
# show "01:02"
display.numbers(1,2)
# show "-5:11"
display.numbers(-5,11)
# show "12:59"
display.numbers(12,59)
# Show Help
display.show('Help')
display.write(display.encode_string('Help'))
# Scroll Hello World from right to left
display.scroll('Hello World') # 4 fps
display.scroll('Hello World', 1000) # 1 fps
# Scroll all available characters
display.scroll(list(nokia7seg._SEGMENTS))
# show temperature '24*C'
display.temperature(24)
display.show('24*C')