Created
November 29, 2016 23:52
-
-
Save lvidarte/5129e4eb7c46544c11c18c2947d483cd to your computer and use it in GitHub Desktop.
Client for Neopixels by Serial
This file contains hidden or 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
from serial import Serial | |
from random import randint | |
import time | |
conn = Serial('/dev/rfcomm0', 57600) | |
def get_value(n): | |
return int(n / 2) | |
def set(index, r, g, b): | |
r = get_value(r) | |
g = get_value(g) | |
b = get_value(b) | |
conn.write(chr(index)) | |
conn.write(chr(128 + r)) | |
conn.write(chr(128 + g)) | |
conn.write(chr(128 + b)) | |
print("led %s (%s, %s, %s)" % (index, r, g, b)) | |
def random(): | |
for index in range(10): | |
r = randint(0, 255) | |
g = randint(0, 255) | |
b = randint(0, 255) | |
set(index, r, g, b) | |
time.sleep(1) | |
def clear(): | |
for i in range(10): | |
set(i, 0, 0, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment