|
6 | 6 |
|
7 | 7 | By updating the buffer being written to the display, the shown digits can be changed.
|
8 | 8 |
|
9 |
| -The main program repeatedly shows random digits which 'lock' after a short |
10 |
| -time. After all digits have locked, it blanks for a short time and then repeats. |
11 |
| -It also demonstrates the use of `asyncio` to perform multiple tasks. |
| 9 | +The main program just counts up, looping back to 0000 after 9999. |
12 | 10 |
|
13 | 11 | This example is designed for a Raspberry Pi Pico and bare LED display. For
|
14 | 12 | simplicity, it is wired without any current limiting resistors, instead relying
|
|
39 | 37 | * Pico GP16 to LED matrix 14 (COM1)
|
40 | 38 | """
|
41 | 39 |
|
42 |
| -import asyncio |
43 |
| -import random |
44 | 40 | import array
|
| 41 | +import time |
45 | 42 | import board
|
46 | 43 | import rp2pio
|
47 | 44 | import adafruit_pioasm
|
@@ -141,38 +138,25 @@ def __setitem__(self, i, v):
|
141 | 138 | else:
|
142 | 139 | self._buf[i] = DIGITS_WT[v] & ~COM_WT[i]
|
143 | 140 |
|
144 |
| - |
145 |
| -async def digit_locker(s, i, wait): |
146 |
| - delay = 30 |
147 |
| - d = random.randint(0, 9) |
148 |
| - while delay < 300: |
149 |
| - d = (d + random.randint(1, 9)) % 10 # Tick to a new digit other than 'd' |
150 |
| - s[i] = d |
151 |
| - await asyncio.sleep(delay / 1000) |
152 |
| - if wait: |
153 |
| - wait -= 1 |
154 |
| - else: |
155 |
| - delay = delay * 1.1 |
| 141 | + def set_number(self, number): |
| 142 | + for j in range(4): |
| 143 | + self[3 - j] = number % 10 |
| 144 | + number //= 10 |
156 | 145 |
|
157 | 146 |
|
158 |
| -def shuffle(seq): |
159 |
| - for i in range(len(seq) - 1): |
160 |
| - j = random.randrange(i + 1, len(seq)) |
161 |
| - seq[i], seq[j] = seq[j], seq[i] |
| 147 | +def count(start=0): |
| 148 | + val = start |
| 149 | + while True: |
| 150 | + yield val |
| 151 | + val += 1 |
162 | 152 |
|
163 | 153 |
|
164 |
| -async def main(): |
165 |
| - waits = [100, 175, 225, 250] |
| 154 | +def main(): |
166 | 155 | with SMSevenSegment(board.GP9) as s:
|
167 |
| - while True: |
168 |
| - shuffle(waits) |
169 |
| - await asyncio.gather( |
170 |
| - *(digit_locker(s, i, di) for i, di in enumerate(waits)) |
171 |
| - ) |
172 |
| - await asyncio.sleep(1) |
173 |
| - for i in range(4): |
174 |
| - s[i] = None |
175 |
| - await asyncio.sleep(0.5) |
176 |
| - |
177 |
| - |
178 |
| -asyncio.run(main()) |
| 156 | + for i in count(): |
| 157 | + s.set_number(i) |
| 158 | + time.sleep(0.05) |
| 159 | + |
| 160 | + |
| 161 | +if __name__ == "__main__": |
| 162 | + main() |
0 commit comments