-
-
Save anishathalye/81e54f4016651f9b67b0e16476ce70e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import time | |
DEVICE = '/dev/ttyUSB0' | |
SPEED = '115200' | |
PWM_MAX = 20 | |
def get_data(color, value): | |
assert color in 'RGB' | |
assert 0 <= value <= PWM_MAX | |
cbit = 'RGB'.index(color) | |
data = cbit << 6 | value | |
return chr(data) | |
def write_color(ser, color, value): | |
data = get_data(color, value) | |
ser.write(data) | |
def main(): | |
ser = serial.Serial(DEVICE, SPEED) | |
ser.setDTR() | |
ser.flushInput() | |
ser.flushOutput() | |
write_color(ser, 'R', 0x0f) | |
time.sleep(0.5) | |
write_color(ser, 'B', 0x0f) | |
time.sleep(0.5) | |
write_color(ser, 'R', 0x00) | |
time.sleep(0.5) | |
write_color(ser, 'B', 0x00) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment