Datasheet
# Run this code when the script is called at the command line:
if __name__ == '__main__':
# Define the number of pixels in the NeoPixel strip.
# Only up to ~340 pixels can be written using the FT232H.
pixel_count = 16
# Create a NeoPixel_FT232H object.
pixels = NeoPixel_FT232H(pixel_count)
# 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)
# 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)
Save the file and navigate to the folder with it in a terminal, then execute the following in Windows to run the program:
python neopixels.py
Or on Mac OSX or Linux execute the following to run the program as root:
sudo python neopixels.py
You should see the NeoPixels light up and animate with different colors. Note that you might need to change the pixel_count
variable in the main part of the program to match the number of pixels in your NeoPixel strip, circle, matrix, etc.
This code does a couple things at a high level. It first defines a class called NeoPixel_FT232H. This class contains some
methods and state which control generating the NeoPixel signal with an FT232H board. The second part of the code uses the
NeoPixel_FT232H class to animate the NeoPixels.
You actually don't need to fully understand the NeoPixel_FT232H class code to use it. This code performs the 'oversampling' by
using a lookup table to expand each byte of color data into 8 bytes of SPI data that approximates the NeoPixel control signal. The
only important thing to know about the NeoPixel_FT232H class is that it exposes a set_pixel_color() function which allows you to
set the red, green, and blue color value of a pixel.
Instead let's walk through a bit of the second half of the code that uses the NeoPixel_FT232H class:
# Run this code when the script is called at the command line:
if __name__ == '__main__':
# Define the number of pixels in the NeoPixel strip.
# Only up to ~340 pixels can be written using the FT232H.
pixel_count = 16
# Create a NeoPixel_FT232H object.
pixels = NeoPixel_FT232H(pixel_count)
© Adafruit Industries https://learn.adafruit.com/adafruit-ft232h-breakout Page 30 of 36










