예제 #1
0
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
예제 #2
0
strip.begin()  # Initialize pins for output
strip.setBrightness(255)  # Limit brightness to ~1/4 duty cycle

# Runs 10 LEDs at a time along strip, cycling through red, green and blue.
# This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel.

head = begin  # Index of first 'on' pixel
tail = -15  # Index of last 'off' pixel
color = 0xFFFFFF  # 'On' color (starts red)

b = 0
while b < 400:
    strip.setPixelColor(b, 0)
    b = b + 1
    print(strip.getPixelColor(b))
strip.show()

while True:  # Loop forever

    strip.setPixelColor(head, color)  # Turn on 'head' pixel
    strip.setPixelColor(tail, 0)  # Turn off 'tail'
    strip.show()  # Refresh strip
    time.sleep(1.0 / 50)  # Pause 20 milliseconds (~50 fps)

    head += 1  # Advance head position
    if (head >= px + begin):  # Off end of strip?
        head = begin  # Reset to start
        #color >>= 8              # Red->green->blue->black
        #if(color == 0): color = 0xAA0000 # If black, reset to red