class StripClient(object): def __init__(self, numpixels): self.numpixels = numpixels self.strip = Adafruit_DotStar(numpixels) self.strip.begin() self.strip.setBrightness(64) def clear(self): self.strip.clear() print("clear") def setBrightness(self, value): self.strip.setBrightness(value) self.strip.show() print("setBrightness:", value) def setPixelColor(self, pixel, color): color_value = ((color[0] & 0xFF) << 8) | ( (color[1] & 0xFF) << 16) | (color[2] & 0xFF) self.strip.setPixelColor(pixel, color_value) self.strip.show() print("setPixelColor:", pixel, color) def show(self): self.strip.show() print("show") def getPixelColor(self): self.strip.getPixelColor() print("getPixelColor") def numPixels(self): return self.strip.numPixels() return self.numpixels def getBrightness(self): return self.strip.getBrightness() return 64
# Here's how to control the strip from any two GPIO pins: datapin = 23 clockpin = 24 strip = Adafruit_DotStar(numpixels, datapin, clockpin) strip.begin() # Initialize pins for output # Load image in RGB format and get dimensions: print "Loading..." img = Image.open(filename).convert("RGB") pixels = img.load() width = img.size[0] height = img.size[1] print "%dx%d pixels" % img.size if height > strip.numPixels(): height = strip.numPixels() # Calculate gamma correction table, makes mid-range colors look 'right': gamma = bytearray(256) for i in range(256): gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5) print "Displaying..." while True: # Loop forever for x in range(width): # For each column of image... for y in range(height): # For each pixel in column... value = pixels[x, y] # Read pixel in image strip.setPixelColor( y, # Set pixel in strip
# Here's how to control the strip from any two GPIO pins: datapin = 23 clockpin = 24 strip = Adafruit_DotStar(numpixels, 32000000) strip.begin() # Initialize pins for output # Load image in RGB format and get dimensions: print "Loading..." img = Image.open(filename).convert("RGB") pixels = img.load() width = img.size[0] height = img.size[1] print "%dx%d pixels" % img.size if (height > strip.numPixels()): height = strip.numPixels() # Calculate gamma correction table, makes mid-range colors look 'right': gamma = bytearray(256) for i in range(256): gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5) print "Displaying..." while True: # Loop forever for x in range(width): # For each column of image... for y in range(height): # For each pixel in column... value = pixels[x, y] # Read pixel in image strip.setPixelColor( y, # Set pixel in strip gamma[value[0]], # Gamma-corrected red
# Here's how to control the strip from any two GPIO pins: datapin = 23 clockpin = 24 strip = Adafruit_DotStar(numpixels, datapin, clockpin) strip.begin() # Initialize pins for output # Load image in RGB format and get dimensions: print("Loading...") img = Image.open(filename).convert("RGB") pixels = img.load() width = img.size[0] height = img.size[1] print("%dx%d pixels" % img.size) if height > strip.numPixels(): height = strip.numPixels() # Calculate gamma correction table, makes mid-range colors look 'right': gamma = bytearray(256) for i in range(256): gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5) print("Displaying...") while True: for x in range(width): for y in range(height): value = pixels[x, y] strip.setPixelColor( y, gamma[value[0]], # Gamma-corrected red
# Here's how to control the strip from any two GPIO pins: datapin = 3 clockpin = 4 strip = Adafruit_DotStar(numpixels, datapin, clockpin) strip.begin() # Initialize pins for output # Load image in RGB format and get dimensions: print "Loading..." img = Image.open(filename).convert("RGB") pixels = img.load() width = img.size[0] height = img.size[1] print "%dx%d pixels" % img.size if(height > strip.numPixels()): height = strip.numPixels() # Calculate gamma correction table, makes mid-range colors look 'right': gamma = bytearray(256) for i in range(256): gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5) print "Displaying..." while True: # Loop forever for x in range(width): # For each column of image... for y in range(height): # For each pixel in column... value = pixels[x, y] # Read pixel in image strip.setPixelColor(y, # Set pixel in strip gamma[value[0]], # Gamma-corrected red gamma[value[1]], # Gamma-corrected green