Datasheet

This portion of code has an if statement that checks if the program is being run from the command line before executing. This is
just a standard Python idiom for defining the main entry point of a program.
Inside the if block you can see the number of pixels is defined and set in the pixel_count variable. Then the NeoPixel_FT232H
object is created by telling it that number of pixels as its only parameter.
# Animate each pixel turning red.
# Loop through each pixel.
for i in range(pixel_count):
# Set the pixel color to pure red.
pixels.set_pixel_color(i, 255, 0, 0)
# Show the pixel buffer by sending it to the LEDs.
pixels.show()
# Delay for a short period of time.
time.sleep(0.25)
# Animate each pixel turning pure green.
for i in range(pixel_count):
pixels.set_pixel_color(i, 0, 255, 0)
pixels.show()
time.sleep(0.25)
# Animate each pixel turning pure blue.
for i in range(pixel_count):
pixels.set_pixel_color(i, 0, 0, 255)
pixels.show()
time.sleep(0.25)
The next section performs a few simple animations that turn each pixel on with primary colors. You can see a loop is used to go
through each pixel and the set_pixel_color() function is called to the pixel color. This function takes 4 parameters, the first is the
number of the pixel (start at 0), and the last 3 parameters are the red, green, and blue color components. Each component
should be a value from 0 to 255, where 0 is no color and 255 is maximum color intensity.
After changing the pixel color, the show() function is called to send the colors to the LEDs. You must call show() in order to make
the NeoPixels light up with the colors you've set previously!
Finally notice the time.sleep() function is used to delay for a short period of time (a quarter of a second in this case). This sleep
function is very useful for animating color changes that should go somewhat slowly.
# Animate a pattern of colors marching around the pixels.
# Create a pattern of colors to display.
colors = [ (255, 0, 0), (255, 255, 0), (0, 255, 0), (0, 255, 255),
(0, 0, 255), (255, 0, 255) ]
offset = 0
print 'Press Ctrl-C to quit.'
while True:
# Loop through all the pixels and set their color based on the pattern.
for i in range(pixel_count):
color = colors[(i+offset)%len(colors)]
pixels.set_pixel_color(i, color[0], color[1], color[2])
pixels.show()
# Increase the offset to make the colors change position.
offset += 1
time.sleep(0.25)
Finally the code enters an infinite loop where it animates a rainbow of colors marching across the pixels. This code uses the
same set_pixel_color() function, but has a little extra logic to pick a color from a list and increase the offset of chosen colors
every loop iteration. Also notice the show() function is again called after updating pixel colors in order to make the LEDs light up
with the desired colors.
That's all there is to controlling NeoPixels with SPI from the FT232H breakout! Feel free to use the code above in your own
NeoPixel projects!
© Adafruit Industries https://learn.adafruit.com/adafruit-ft232h-breakout Page 31 of 36