esp-artnet-http-to-dmx/dmx.py

34 lines
959 B
Python

from machine import UART, Pin
import time
from array import array
tx_pins = [1, 17]
class universe():
def __init__(self, uartport, dirselectport):
self.uartport = uartport
self.dirselect = Pin(dirselectport, Pin.OUT)
dmx_uart = uart = UART(uartport)
del(dmx_uart)
self.dmx_values = array('B', [0] * 513)
def get_rgb(self, address):
return {'r': dmx.dmx_values[address], 'g': dmx.dmx_values[address+1], 'b': dmx.dmx_values[address+2]}
def set_channels(self, frame):
for ch in frame:
self.dmx_values[ch] = frame[ch]
def write_frame(self):
self.dirselect.value(1)
dmx_uart = Pin(tx_pins[self.uartport], Pin.OUT)
dmx_uart.value(0)
time.sleep_us(74)
dmx_uart.value(1)
dmx_uart = UART(self.uartport)
dmx_uart.init(115200, bits=8, parity=None, stop=2)
dmx_uart.write(self.dmx_values)
del(dmx_uart)