st-ten-1/src/test/neo_lights.py

30 lines
583 B
Python
Raw Normal View History

2023-03-13 17:31:17 +00:00
import platform
2022-08-01 11:29:12 +00:00
import time
2022-06-29 09:58:24 +00:00
from ctypes import c_uint32
import serial
2023-03-13 17:31:17 +00:00
if platform.system() == "windows":
port="COM4"
else:
port="/dev/ttyACM0"
2022-06-29 09:58:24 +00:00
C_UINT32_MAX = c_uint32(-1).value
conn = serial.Serial(
2023-03-13 17:31:17 +00:00
port=port,
2022-06-29 09:58:24 +00:00
baudrate=9600,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS,
2022-08-01 11:29:12 +00:00
rtscts=False,
xonxoff=False
2022-06-29 09:58:24 +00:00
)
pixel = C_UINT32_MAX
2022-08-01 11:29:12 +00:00
time.sleep(5)
2022-06-29 09:58:24 +00:00
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()