st-ten-1/src/test/neo_lights.py
2023-03-13 18:31:17 +01:00

30 lines
583 B
Python

import platform
import time
from ctypes import c_uint32
import serial
if platform.system() == "windows":
port="COM4"
else:
port="/dev/ttyACM0"
C_UINT32_MAX = c_uint32(-1).value
conn = serial.Serial(
port=port,
baudrate=9600,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS,
rtscts=False,
xonxoff=False
)
pixel = C_UINT32_MAX
time.sleep(5)
color = "#ff00ff"
conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
response = conn.readline()
print(response)
conn.close()