From 7997057de145b9900426379772f46718bd563529 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Thu, 8 Feb 2018 12:56:59 -0700 Subject: [PATCH 1/2] added examples folder and .py file --- examples/randomcolor.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/randomcolor.py diff --git a/examples/randomcolor.py b/examples/randomcolor.py new file mode 100644 index 0000000..fe86411 --- /dev/null +++ b/examples/randomcolor.py @@ -0,0 +1,28 @@ +import time +import random +import board +import adafruit_dotstar as dotstar + +# One pixel connected internally on a GEMMA M0 +dots = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) + +# With a Dotstar Digital LEB Strip with 30 lights +#dots = dotstar.DotStar(board.SCK, board.MOSI, 30, brightness=0.2) + +######################### HELPERS ############################## + +# a random color 0 -> 224 +def rndc(): + return random.randrange(0, 7) * 32 + +######################### MAIN LOOP ############################## +n = len(dots) +while True: + #fill each dot with a random color1 + for dot in range(n): + dots[dot] = (rndc(), rndc(), rndc()) + + # show all dots in strip + dots.show() + + time.sleep(.25) From e64dd6febadc01988a6163f821201708cd8fd98b Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Fri, 9 Feb 2018 09:08:44 -0700 Subject: [PATCH 2/2] improved code sample --- examples/randomcolor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/randomcolor.py b/examples/randomcolor.py index fe86411..a21f182 100644 --- a/examples/randomcolor.py +++ b/examples/randomcolor.py @@ -12,15 +12,15 @@ ######################### HELPERS ############################## # a random color 0 -> 224 -def rndc(): +def random_color(): return random.randrange(0, 7) * 32 ######################### MAIN LOOP ############################## -n = len(dots) +n_dots = len(dots) while True: - #fill each dot with a random color1 - for dot in range(n): - dots[dot] = (rndc(), rndc(), rndc()) + #fill each dot with a random color + for dot in range(n_dots): + dots[dot] = (random_color(), random_color(), random_color()) # show all dots in strip dots.show()