-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_leds.py
More file actions
75 lines (53 loc) · 1.46 KB
/
run_leds.py
File metadata and controls
75 lines (53 loc) · 1.46 KB
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
import asyncio
import random
import threading
import time
import socket
from dataclasses import dataclass
import board
import neopixel
import concurrent.futures
@dataclass
class Instruction:
R: int
G: int
B: int
pixel_pin = board.D18
num_pixels = 150
ORDER = neopixel.GRB
brightness = 3
pixels = neopixel.NeoPixel(
pixel_pin, num_pixels, brightness=255, pixel_order=ORDER, auto_write=False
)
# clears the strip if its currently active
pixels.fill((0, 0, 0))
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('192.168.1.11', 5555)
sock.bind(server_address)
print("Awaiting data...")
colour = (0, 0, 0)
def Initiate_Conn():
while True:
data, address = sock.recvfrom(1024)
if data:
print("Processing data")
Process_Byte_Array(data)
pixels.show()
print("Displaying")
else:
print("No data from ", address)
break
sock.close()
def Process_Byte_Array(data):
start = time.time()
size = int(len(data) / 3)
print(size)
for i in range(size):
byteArrayIndex = i * 3
pixels[i] = (data[byteArrayIndex], data[byteArrayIndex + 1], data[byteArrayIndex + 2])
end = time.time()
print(f"timer: {end - start}")
async def main():
networkThread = threading.Thread(target=Initiate_Conn)
networkThread.start()
asyncio.run(main())