0

Two Neopixel Ring Demo
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Two Neopixel Ring Demo

by geekguy on Fri Aug 09, 2019 10:11 pm

Hi,

I started this from the a standard Adafruit demo, and modified the color_chase() and rainbow_cycle() routines so they will work with any size ring(s). One pin is used for each ring. Here is a short video of this in action. This is 100% #Circuitpython.

Here is the code:
Code: Select all | TOGGLE FULL SIZE
#   Two Neopixel Ring Demo
import time
import board
import neopixel

COLOR_WAIT_SEC = 0.07

onboardPin = board.NEOPIXEL

#   First Ring
ring12Pin = board.D9
ring12Pixels = 12

#   Second Ring
ring16Pin = board.D10
ring16Pixels = 16

#   Initialize the rings
onboard = neopixel.NeoPixel(onboardPin, 1, brightness = 0.1, auto_write = False)
ring12 = neopixel.NeoPixel(ring12Pin, ring12Pixels, brightness = 0.1, auto_write = False, bpp = 4)
ring16 = neopixel.NeoPixel(ring16Pin, ring16Pixels, brightness = 0.1, auto_write = False, bpp = 4)

#   The size of the ring(s) that count pixels in the opposite direction
OPPOSITES = [16]

RED = (255, 0, 0, 0)
YELLOW = (255, 150, 0, 0)
GREEN = (0, 255, 0, 0)
CYAN = (0, 255, 255, 0)
BLUE = (0, 0, 255, 0)
PURPLE = (180, 0, 180, 0)
BLACK = (0, 0, 0, 0)
WHITE = (0, 0, 0, 127)

def init_rings():
   #   Turn off the onboard Neopixel
   onboard[0] = (0, 0, 0)
   onboard.show()
   
   #   Turn off the rings
   ring12.fill(BLACK)
   ring12.show()
   ring16.fill(BLACK)
   ring16.show()

def wheel(pos):
   #   Input a value 0 to 255 to get a color value.
   #   The colours are a transition r - g - b - w - back to r.
   if pos < 0 or pos > 255:
      return (0, 0, 0, 0)
   if pos < 85:
      return (255 - pos * 3, pos * 3, 0)
   if pos < 170:
      pos -= 85
      return (0, 255 - pos * 3, pos * 3, 0)

   pos -= 170
   return (pos * 3, 0, 255 - pos * 3, 0)

def color_chase(ring, color, wait):
   nPixels = len(ring)
   
   if (nPixels in OPPOSITES):
      first = nPixels - 1
      last = -1
      increment = -1
   else:
      first = 0
      last = nPixels
      increment = 1
   
   for i in range(first, last, increment):
      ring[i] = color
      ring.show()
      time.sleep(wait)

   time.sleep(0.5)

def rainbow_cycle(ring, wait):
   nPixels = len(ring)
   
   for j in range(650):
      for i in range(nPixels):
         rc_index = (i * 256 // nPixels) + j
         ring[i] = wheel(rc_index & 255)

      ring.show()

      time.sleep(wait)

init_rings()

try:
   while True:
      ring12.fill(RED)
      ring12.show()
      # Increase or decrease to change the speed of the solid color change.
      time.sleep(1)
      ring12.fill(GREEN)
      ring12.show()
      time.sleep(1)
      ring12.fill(BLUE)
      ring12.show()
      time.sleep(1)
      ring12.fill(WHITE)
      ring12.show()
      time.sleep(1)
      ring12.fill(PURPLE)
      ring12.show()
      time.sleep(1)
      ring12.fill(YELLOW)
      ring12.show()
      time.sleep(1)
      ring12.fill(BLACK)
      ring12.show()
      time.sleep(1)

      color_chase(ring12, RED, COLOR_WAIT_SEC)  # Increase the number to slow down the color chase
      color_chase(ring12, YELLOW, COLOR_WAIT_SEC)
      color_chase(ring12, GREEN, COLOR_WAIT_SEC)
      color_chase(ring12, BLUE, COLOR_WAIT_SEC)
      color_chase(ring12, CYAN, COLOR_WAIT_SEC)
      color_chase(ring12, PURPLE, COLOR_WAIT_SEC)
      color_chase(ring12, WHITE, COLOR_WAIT_SEC)

      time.sleep(0.2)

      rainbow_cycle(ring12, 0)  # Increase the number to slow down the rainbow
      time.sleep(0.2)
      
      color_chase(ring12, BLACK, COLOR_WAIT_SEC)
      time.sleep(1)
      
      ring16.fill(RED)
      ring16.show()
      # Increase or decrease to change the speed of the solid color change.
      time.sleep(1)
      ring16.fill(GREEN)
      ring16.show()
      time.sleep(1)
      ring16.fill(BLUE)
      ring16.show()
      time.sleep(1)
      ring16.fill(WHITE)
      ring16.show()
      time.sleep(1)
      ring16.fill(PURPLE)
      ring16.show()
      time.sleep(1)
      ring16.fill(YELLOW)
      ring16.show()
      time.sleep(1)
      ring16.fill(BLACK)
      ring16.show()
      time.sleep(1)

      color_chase(ring16, RED, COLOR_WAIT_SEC)  # Increase the number to slow down the color chase
      color_chase(ring16, YELLOW, COLOR_WAIT_SEC)
      color_chase(ring16, GREEN, COLOR_WAIT_SEC)
      color_chase(ring16, BLUE, COLOR_WAIT_SEC)
      color_chase(ring16, CYAN, COLOR_WAIT_SEC)
      color_chase(ring16, PURPLE, COLOR_WAIT_SEC)
      color_chase(ring16, WHITE, COLOR_WAIT_SEC)

      time.sleep(0.2)

      rainbow_cycle(ring16, 0)  # Increase the number to slow down the rainbow
      time.sleep(0.2)
      
      color_chase(ring16, BLACK, COLOR_WAIT_SEC)
      time.sleep(2)
except KeyboardInterrupt:
   init_rings()

Now, I am working on a version that will work with any number of rings chained together as one strip. I can already get a list of pixel numbers that belong to each ring. Now, I just have to figure out how to use that data in the demo to get the same results.

Enjoy!

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: Two Neopixel Ring Demo

by geekguy on Sat Aug 10, 2019 4:05 pm

Hi,

Here is my first video of using chained Neopixel rings. The chaining is really very simple - just connect the data output pin of one ring, stick, or strip to the data input of the next one. I will now work on two more complex routines for chained Neopixels - color_chase() and rainbow_cycle().

Enjoy!

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: Two Neopixel Ring Demo

by geekguy on Sat Aug 10, 2019 7:00 pm

Hi,

Here is the current code for my chained Neopixel rings. I forgot to include it in my last post.

Code: Select all | TOGGLE FULL SIZE
# CircuitPython Demo - Chained NeoPixels
import time
import board
import neopixel
import random

COLOR_WAIT_SEC = 0.07

RED = (255, 0, 0, 0)
YELLOW = (255, 150, 0, 0)
GREEN = (0, 255, 0, 0)
CYAN = (0, 255, 255, 0)
BLUE = (0, 0, 255, 0)
PURPLE = (180, 0, 180, 0)
WHITE = (0, 0, 0, 127)
BLACK = (0, 0, 0, 0)

colorList = [RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE]

print()
print()
print("colorList = {0}".format(colorList))

onboardPin = board.NEOPIXEL

ringSet = [12, 16]

ringsPin = board.D9
ringsPixels = 0

#   Calculate the total number of pixels for the rings that are chained
for pixel in ringSet:
   ringsPixels += pixel

print("ringsPixels = {0}".format(ringsPixels))

onboard = neopixel.NeoPixel(onboardPin, 1, brightness = 0.1, auto_write = False)
rings = neopixel.NeoPixel(ringsPin, ringsPixels, brightness = 0.1, auto_write = False, bpp = 4)

rings.fill(BLACK)
rings.show()

#   Build a list of pixel numbers. There will be a list of actual
#      pixel numbers.
pixelList = []
for i in range(0, ringsPixels):
   pixelList = pixelList + [i]
   
position = 0
ringCount = 0
ringList = []

print("ringSet = {0}".format(ringSet))

#   Build a list of lists for the rings.
for ringSize in ringSet:
   ringCount += 1
   ringList += [pixelList[position:position + ringSize]]
   position = position + ringSize
   print("ringCount = {0}, position = {1}".format(ringCount, position))

for i in range(ringCount):
   print("ringList[{0}] = {1}, length = {2}".format(i, ringList[i], len(ringList[i])))
   
OPPOSITES = [16]

#   Fill a ring with a defined color
def fillColor(ring, color, cList):
   for i in range(0, len(ring)):
      rings[ring[i]] = color

#   Fill a ring with a random color
def fillRandomColor(ring, cList):
   colorNumber = random.randint(0, len(cList) - 1)
   print("colorNumber = {0}".format(colorNumber))
   color = cList[colorNumber]
   
   print("color = {0}".format(color))

   for i in range(0, len(ring)):
      rings[ring[i]] = color

# Turn off the onboard Neopixel
onboard[0] = (0, 0, 0)
onboard.show()

try:
   #   Start filling the rings with random colors.
   while True:
      for i in range(0, len(ringList)):
         print("i = {0}".format(i))
         fillRandomColor(ringList[i], colorList)

      rings.show()
      
      time.sleep(1)
except KeyboardInterrupt:
   rings.fill(BLACK)
   rings.show()

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: Two Neopixel Ring Demo

by siddacious on Sun Aug 11, 2019 3:21 am

This is great work! Thanks for sharing.

siddacious
 
Posts: 126
Joined: Fri Apr 21, 2017 3:09 pm

Re: Two Neopixel Ring Demo

by geekguy on Sun Aug 11, 2019 12:23 pm

siddacious wrote:This is great work! Thanks for sharing.

I can address individual pixels in each ring now.

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: Two Neopixel Ring Demo

by geekguy on Tue Aug 13, 2019 10:01 pm

Hi,

I had to make sure my software would really run with more than two Neopixel devices chained together. Here is the resulting video . A 12 pixel ring, 8 pixel stick, and 16 pixel ring, in that order for a total of 36 pixels. This way too fun!!

Here is my current code:
Code: Select all | TOGGLE FULL SIZE
# CircuitPython Demo - Chained NeoPixels
import time
import board
import neopixel
import random

RED = (127, 0, 0, 0)
YELLOW = (127, 75, 0, 0)
GREEN = (0, 127, 0, 0)
CYAN = (0, 127, 127, 0)
BLUE = (0, 0, 127, 0)
PURPLE = (90, 0, 90, 0)
WHITE = (0, 0, 0, 127)
BLACK = (0, 0, 0, 0)

COLOR_WAIT_SEC = 0.05
   
OPPOSITES = [12]
CHASE_COLORS = None

COLOR_LIST = [RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE]
COLOR_NAMES = ["RED", "YELLOW", "GREEN", "CYAN", "BLUE", "PURPLE", "WHITE"]

#   This is your set of strips, in order on the chain
STRIP_SET = [12, 8, 16]

print()
print()
print("COLOR_LIST = {0}".format(COLOR_LIST))

onboardPin = board.NEOPIXEL

stripsPin = board.D5
stripsPixels = 0

#   Calculate the total number of pixels for the strips that are chained
for pixel in STRIP_SET:
   stripsPixels += pixel

print("stripsPixels = {0}".format(stripsPixels))

onboard = neopixel.NeoPixel(onboardPin, 1, brightness = 0.1, auto_write = False)
strips = neopixel.NeoPixel(stripsPin, stripsPixels, brightness = 0.05, auto_write = False, bpp = 4)

#   Turn off all the strips
strips.fill(BLACK)
strips.show()

#   Turn off the onboard Neopixel
onboard[0] = (0, 0, 0)
onboard.show()

#   Build a list of pixel numbers. There will be a list of actual
#      pixel numbers.
pixelList = []
for i in range(0, stripsPixels):
   pixelList = pixelList + [i]
   
position = 0
stripCount = 0
stripList = []

print("STRIP_SET = {0}".format(STRIP_SET))

#   Build a list of lists for the strips.
for stripSize in STRIP_SET:
   stripCount += 1
   stripList += [pixelList[position:position + stripSize]]
   position = position + stripSize
   print("stripCount = {0}, position = {1}".format(stripCount, position))

for stripNr in range(stripCount):
   print("stripList[{0}] = {1}, length = {2}".format(stripNr, stripList[stripNr], len(stripList[stripNr])))

#   Pick a random color
def randomColor(cList):
   colorNr = random.randint(0, len(cList) - 1)
   return cList[colorNr]
      
#   Set a pixel of a strip to a color
def setPixel(strip, pixelNr, color):
   strips[strip[pixelNr]] = color
   
#   Fill a strip with a defined color
def fillSingleColor(strip, color):
   for i in range(0, len(strip)):
      strips[strip[i]] = color

#   Fill a strip with a random color
def fillRandomColor(strip, cList):
   color = randomColor(cList)
   colorNr = cList.index(color, 0)
   
   print("color = {0} ({1})".format(color, COLOR_NAMES[colorNr]))

   for i in range(0, len(strip)):
      strips[strip[i]] = color

'''
   colorChaseMulti(strips, color, wait):
   
   strips = The entire strip of pixels, including chained strips
   color = Either a single color tuple OR a list of color tuples
   wait = How long to wait between pixel drawings   
'''
def colorChaseMulti(strps, color, wait):
   maxPixels = max(STRIP_SET)
   '''
   if (nPixels in OPPOSITES):
      #   For rings that count pixels in the opposite direction
      first = 0
      last = nPixels
      increment = 1
   else:
      #   Normal direction
      first = nPixels - 1
      last = -1
      increment = -1
   '''
   
   sPos = []
   
   for i in range(stripCount):
      sPos += [0]

   pixelCount = 0
   position = 0
   nPixels = 0
   
   while (pixelCount < maxPixels):
      for stripNr in range(stripCount):
         strip = stripList[stripNr]
         nPixels = len(strip)
         #print("nPixels = {0}, stripNr = {1}".format(nPixels, stripNr))
         #print("strip = {0}".format(strip))
         
         if (sPos[stripNr] < nPixels):
            if (isinstance(color, list)):
               index = COLOR_LIST.index(color[stripNr])
               print("stripNr = {0}, color = {1} ({2})".format(stripNr + 1, color[stripNr], COLOR_NAMES[index]))
               stripColor = color[stripNr]
            elif (isinstance(color, tuple)):
               index = COLOR_LIST.index(color)
               print("stripNr = {0}, color = {1} ({2})".format(stripNr + 1, color, COLOR_NAMES[index]))
               stripColor = color
            else:
               print("color is invalid")
               raise(ValueError)

            position = strip[sPos[stripNr]]
            print("position = {0}".format(position))
            strps[position] = stripColor
            sPos[stripNr] += 1

      time.sleep(wait)

      print("sPos = {0}".format(sPos))
      pixelCount += 1
      strps.show()

   time.sleep(0.5)

print()
print("Chained Neopixel Demo - Press Ctrl/C to exit")
print()

try:
   #   Start filling the strips with random colors.
   while True:
      #   Fill each strip with a random color
      print("Standard fill with random colors")
      
      for stripNr in range(0, len(stripList)):
         fillRandomColor(stripList[stripNr], COLOR_LIST)

      strips.show()
      time.sleep(2)
      
      print()
      strips.fill(BLACK)
      strips.show()
      time.sleep(0.5)

      #   Show the first three pixels as Red, Green, Blue. The last
      #      pixel of the strip is white.
      print("Showing direction of pixel counting, RGB, and last pixel")

      #   The first pixel
      setPixel(stripList[0], 0, RED)
      setPixel(stripList[1], 0, RED)
      setPixel(stripList[2], 0, RED)
      
      #   The second pixel
      setPixel(stripList[0], 1, GREEN)
      setPixel(stripList[1], 1, GREEN)
      setPixel(stripList[2], 1, GREEN)
      
      #   The third pixel
      setPixel(stripList[0], 2, BLUE)
      setPixel(stripList[1], 2, BLUE)
      setPixel(stripList[2], 2, BLUE)
      
      #   The last pixel
      setPixel(stripList[0], STRIP_SET[0] - 1, WHITE)
      setPixel(stripList[1], STRIP_SET[1] - 1, WHITE)
      setPixel(stripList[2], STRIP_SET[2] - 1, WHITE)
      strips.show()                                                     
      time.sleep(2)

      print("Testing colorChaseMulti()")
      strips.fill(BLACK)
      strips.show()
      time.sleep(0.5)
      
      colorNr = random.randint(0, len(COLOR_LIST) - 1)
      color = COLOR_LIST[colorNr]
      
      colorChaseMulti(strips, color, 0.05)
      time.sleep(2)

      strips.fill(BLACK)
      strips.show()
      time.sleep(1)
      
      colorChaseMulti(strips, [randomColor(COLOR_LIST), randomColor(COLOR_LIST), randomColor(COLOR_LIST)], 0.05)
      time.sleep(2)
      
      strips.fill(BLACK)
      strips.show()
      time.sleep(2)
      print()
except KeyboardInterrupt:
   strips.fill(BLACK)
   strips.show()

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: Two Neopixel Ring Demo

by geekguy on Fri Aug 16, 2019 4:03 pm

Hi,

Here is the final video of my new version of color_chase() from the original #Adafruit demo. I slowed down the fill speed in order to make the directions of fill easier to see, and so it would be more obvious which thing(s) were reversed.

Pay close attention to the direction of fill for the #Neopixel rings and stick!

There will be two parts with no reversal, then two parts with the large ring only reversed, then two parts with the small ring and stick only reversed. Things go back to normal with no reversal after that and the sequence restarts at the top.

This is all done under script control in #Circuitpython!
This script was created from the original #Adafruit demo.
My next trick will be to modify the rainbow_chase() routine to work the same say as the new colorChaseMulti() routine works.

Here is my current code for this demo:
Code: Select all | TOGGLE FULL SIZE
# CircuitPython Demo - Chained NeoPixels
import time
import board
import neopixel
import random

#   The delay, in seconds, between pixels of a color chase
COLOR_WAIT_SEC = 0.04

#   Put the length of your strips, in order, into this list
STRIP_SET = [12, 8, 16]

#   If you want to reverse the direction of fill for a strip, or set of
#      strips, put the length of the strip into this list. It will
#      reverse clockwise to counter clockwise and vice versa.
OPPOSITES = []

RED = (127, 0, 0, 0)
YELLOW = (127, 75, 0, 0)
GREEN = (0, 127, 0, 0)
CYAN = (0, 127, 127, 0)
BLUE = (0, 0, 127, 0)
PURPLE = (90, 0, 90, 0)
WHITE = (0, 0, 0, 127)
BLACK = (0, 0, 0, 0)

COLOR_LIST = [RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE]
COLOR_NAMES = ["RED", "YELLOW", "GREEN", "CYAN", "BLUE", "PURPLE", "WHITE"]

print()
print("Three pixel ring chained demo - Press Ctrl/C to exit")
print()

onboardPin = board.NEOPIXEL

stripsPin = board.D5
stripsPixels = 0

#   Calculate the total number of pixels for the strips that are chained
for pixel in STRIP_SET:
   stripsPixels += pixel

print("stripsPixels = {0}".format(stripsPixels))

onboard = neopixel.NeoPixel(onboardPin, 1, brightness = 0.1, auto_write = False)
strips = neopixel.NeoPixel(stripsPin, stripsPixels, brightness = 0.05, auto_write = False, bpp = 4)

#   Turn off the main strip
strips.fill(BLACK)
strips.show()

#   Turn off the onboard Neopixel
onboard[0] = (0, 0, 0)
onboard.show()

#   Build a list of pixel numbers. There will be a list of actual
#      pixel numbers.
pixelList = []

for i in range(0, stripsPixels):
   pixelList = pixelList + [i]
   
position = 0
stripCount = 0
stripList = []

print("STRIP_SET = {0}".format(STRIP_SET))

#   Build a list of lists for the strips.
for stripSize in STRIP_SET:
   stripCount += 1
   stripList += [pixelList[position:position + stripSize]]
   position = position + stripSize
   print("stripCount = {0}, position = {1}".format(stripCount, position))

print()

#   Pick a random color
def randomColor(cList):
   colorNr = random.randint(0, len(cList) - 1)
   return cList[colorNr]
      
#   Set a pixel of a strip to a color
def setPixel(strip, pixelNr, color):
   strips[strip[pixelNr]] = color
   
#   Fill a strip with a defined color
def fillSingleColor(strip, color):
   stripNr = stripList.index(strip)
   colorNr = COLOR_LIST.index(color)

   print("stripNr = {0}, color = {1} ({2})".format(stripNr, color, COLOR_NAMES[colorNr]))

   for pixelNr in range(0, len(strip)):
      strips[strip[pixelNr]] = color

#   Fill a strip with a random color
def fillRandomColor(strip, cList):
   color = randomColor(cList)
   colorNr = cList.index(color, 0)
   stripNr = stripList.index(strip)

   print("stripNr = {0}, color = {1} ({2})".format(stripNr, color, COLOR_NAMES[colorNr]))

   for pixelNr in range(0, len(strip)):
      strips[strip[pixelNr]] = color

'''
   colorChaseMulti(strips, color, wait):
   
   strips = The entire strip of pixels, including chained strips
   color = Either a single color tuple OR a list of color tuples
   wait = How long to wait between pixel drawings   
'''
def colorChaseMulti(strps, color, wait):
   maxPixels = max(STRIP_SET)
   
   sPos = []
   
   for stripNr in range(stripCount):
      if STRIP_SET[stripNr] in OPPOSITES:
         sPos += [STRIP_SET[stripNr] - 1]
      else:
         sPos += [0]

   pixelCount = 0
   position = 0
   nPixels = 0
   stripTrack = []
   
   while (pixelCount < maxPixels):
      for stripNr in range(stripCount):
         strip = stripList[stripNr]
         nPixels = len(strip)
         
         if nPixels in OPPOSITES:
            left = -1
            right = sPos[stripNr]
         else:
            left = sPos[stripNr]
            right = nPixels

         if (left < right):
            if (isinstance(color, list)):
               index = COLOR_LIST.index(color[stripNr])
               
               if (not (stripNr in stripTrack) ):
                  print("stripNr = {0}, color = {1} ({2})".format(stripNr, color[stripNr], COLOR_NAMES[index]))

               stripColor = color[stripNr]
            elif (isinstance(color, tuple)):
               index = COLOR_LIST.index(color)

               if (not (stripNr in stripTrack) ):
                  print("stripNr = {0}, color = {1} ({2})".format(stripNr, color, COLOR_NAMES[index]))

               stripColor = color
            else:
               print("color is invalid")
               raise(ValueError)
            
            if (not (stripNr in stripTrack) ):
               stripTrack += [stripNr]

            position = strip[sPos[stripNr]]
            strps[position] = stripColor
            
            if nPixels in OPPOSITES:
               sPos[stripNr] -= 1
            else:
               sPos[stripNr] += 1

         strps.show()
         
         if (wait > 0.0):
            time.sleep(wait)

      pixelCount += 1

   stripTrack = []      

try:
   #   Start filling the strips with random colors.
   while True:
      print("------------------------------------------------------")
      print()
      print("Showing standard fill with a single color")

      color = randomColor(COLOR_LIST)

      for stripNr in range(stripCount):
         fillSingleColor(stripList[stripNr], color)

      strips.show()
      time.sleep(3)

      strips.fill(BLACK)
      strips.show()
      time.sleep(0.5)

      print()
      print("Showing standard fill with multiple colors")

      for stripNr in range(0, len(stripList)):
         fillRandomColor(stripList[stripNr], COLOR_LIST)

      strips.show()
      time.sleep(3)
      
      print()
      strips.fill(BLACK)
      strips.show()
      time.sleep(0.5)

      #   Showing RED, GREEN, BLUE for direction of counting. RED is
      #      pixel zero. The last pixel of the strip is WHITE.
      print("Showing pixel counting direction of each strip")
      #   The first pixel
      setPixel(stripList[0], 0, RED)
      setPixel(stripList[1], 0, RED)
      setPixel(stripList[2], 0, RED)
      
      #   The second pixel
      setPixel(stripList[0], 1, GREEN)
      setPixel(stripList[1], 1, GREEN)
      setPixel(stripList[2], 1, GREEN)
      
      #   The third pixel
      setPixel(stripList[0], 2, BLUE)
      setPixel(stripList[1], 2, BLUE)
      setPixel(stripList[2], 2, BLUE)
      
      #   The last pixel
      setPixel(stripList[0], STRIP_SET[0] - 1, WHITE)
      setPixel(stripList[1], STRIP_SET[1] - 1, WHITE)
      setPixel(stripList[2], STRIP_SET[2] - 1, WHITE)

      strips.show()      
      time.sleep(3)

      strips.fill(BLACK)
      strips.show()
      time.sleep(0.5)

      #   Setting both disks and the stick to fill in their normal directions
      OPPOSITES = []
      
      print()
      print("Testing colorChaseMulti() with one color (No reversal)")

      colorNr = random.randint(0, len(COLOR_LIST) - 1)
      color = COLOR_LIST[colorNr]
      
      colorChaseMulti(strips, color, COLOR_WAIT_SEC)
      time.sleep(4)

      strips.fill(BLACK)
      strips.show()
      time.sleep(1)
      
      print()
      print("Testing colorChaseMulti() with multiple colors (No reversal)")
      colorChaseMulti(strips, [randomColor(COLOR_LIST), randomColor(COLOR_LIST), randomColor(COLOR_LIST)], COLOR_WAIT_SEC)
      time.sleep(4)
      
      strips.fill(BLACK)
      strips.show()
      time.sleep(1)

      #   Setting the 16 pixel disk to fill in the opposite direction
      OPPOSITES = [16]
      
      print()
      print("Testing colorChaseMulti() with one color (Reversed 16)")

      colorNr = random.randint(0, len(COLOR_LIST) - 1)
      color = COLOR_LIST[colorNr]
      
      colorChaseMulti(strips, color, COLOR_WAIT_SEC)
      time.sleep(4)

      strips.fill(BLACK)
      strips.show()
      time.sleep(1)
      
      print()
      print("Testing colorChaseMulti() with multiple colors (Reversed 16)")
      colorChaseMulti(strips, [randomColor(COLOR_LIST), randomColor(COLOR_LIST), randomColor(COLOR_LIST)], COLOR_WAIT_SEC)
      time.sleep(4)

      strips.fill(BLACK)
      strips.show()
      time.sleep(1)

      #   Setting the 8 pixel stick and 12 pixel disk to fill in the opposite direction
      OPPOSITES = [8, 12]
      
      print()
      print("Testing colorChaseMulti() with one color (Reversed 8 and 12)")

      colorNr = random.randint(0, len(COLOR_LIST) - 1)
      color = COLOR_LIST[colorNr]
      
      colorChaseMulti(strips, color, COLOR_WAIT_SEC)
      time.sleep(4)

      strips.fill(BLACK)
      strips.show()
      time.sleep(1)
      
      print()
      print("Testing colorChaseMulti() with multiple colors (Reversed 8 and 12)")
      colorChaseMulti(strips, [randomColor(COLOR_LIST), randomColor(COLOR_LIST), randomColor(COLOR_LIST)], COLOR_WAIT_SEC)
      time.sleep(4)
            
      strips.fill(BLACK)
      strips.show()
      time.sleep(1)

      #   Setting everything back normal directions
      OPPOSITES = []

      print()
      print("Testing colorChaseMulti() with one color (No reversal)")

      colorNr = random.randint(0, len(COLOR_LIST) - 1)
      color = COLOR_LIST[colorNr]
      
      colorChaseMulti(strips, color, COLOR_WAIT_SEC)
      time.sleep(4)

      strips.fill(BLACK)
      strips.show()
      time.sleep(1)
      
      print()
      print("Testing colorChaseMulti() with multiple colors (No reversal)")
      colorChaseMulti(strips, [randomColor(COLOR_LIST), randomColor(COLOR_LIST), randomColor(COLOR_LIST)], COLOR_WAIT_SEC)
      time.sleep(4)
      
      strips.fill(BLACK)
      strips.show()
      time.sleep(1)
      
      print()
except KeyboardInterrupt:
   strips.fill(BLACK)
   strips.show()

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Please be positive and constructive with your questions and comments.