class WallClock(object):
    def __init__(self):
        # Create a NeoPixel object with 60 LEDs
        # and turn down the brightness
        self._strip=NeoPixel(60)
        self._strip.begin()
        self._strip.setBrightness(.25)
        self._strip.show()

    def tick(self):
        # Schedule the next tick to limit drift
        self._timer=Timer(1., self.tick)
        self._timer.start()

        # Get the current time
        now=datetime.now()
        second=now.second
        minute=now.minute
        hour=now.hour

        # Adjust 24hr time to 12hr time
        if hour>=12: hour-=12

        # The hour is shown at every 5th LED
        hour*=5

        # Clear the display
        self.clear()

        # Set the hour LED to blue
        self._strip.setPixelColor(hour, 0, 0, 255)

        # Set the minute LED to red unless the minute
        # hour LED are the same then alternate the colour
        # between red and blue every second
        if hour==minute and second%2:
            self._strip.setPixelColor(minute, 0, 0, 255)
        else: self._strip.setPixelColor(minute, 255, 0, 0)

        # Set the second LED to green
        self._strip.setPixelColor(second, 0, 255, 0)

        # Update the display
        self._strip.show()

    def clear(self):
        # Set every pixel off
        for i in range(60):
            self._strip.setPixelColor(i, 0, 0, 0)
        self._strip.show()
Exemple #2
0
    if b < 0:
        b = 0
    c = Color()
    c.r = int(r * 255)
    c.g = int(g * 255)
    c.b = int(b * 255)
    return c


# Creates a rainbow of all colors across all leds
# The rainbow slides around once per minute
if __name__ == "__main__":
    pixels = 27  # how many leds do you have.
    n = NeoPixel(pixels)
    n.setBrightness(1.0)
    while 1:
        (fractionOfMinute, dummy) = modf(time() / 60.0)
        for i in range(0, pixels - 1):
            p = i / float(pixels)  # 0.0..1.0 by position on string
            q = p + fractionOfMinute
            while q > 1:
                q = q - 1.0  # normalize for overflow
            (r, g, b) = colorsys.hsv_to_rgb(q, 1.0, 1.0)
            n.setPixelColor(i, toNeoPixelColor(r, g, b))
        n.show()
        sleep(0.2)
    n.clear()
    n.show()
    del n
    exit(0)
Exemple #3
0
    if b < 0:
        b = 0
    c = Color()
    c.r = int(r * 255)
    c.g = int(g * 255)
    c.b = int(b * 255)
    return (c)


# Creates a rainbow of all colors across all leds
# The rainbow slides around once per minute
if __name__ == "__main__":
    pixels = 27  # how many leds do you have.
    n = NeoPixel(pixels)
    n.setBrightness(1.)
    while (1):
        (fractionOfMinute, dummy) = modf(time() / 60.0)
        for i in range(0, pixels - 1):
            p = i / float(pixels)  # 0.0..1.0 by position on string
            q = p + fractionOfMinute
            while (q > 1):
                q = q - 1.0  # normalize for overflow
            (r, g, b) = colorsys.hsv_to_rgb(q, 1.0, 1.0)
            n.setPixelColor(i, toNeoPixelColor(r, g, b))
        n.show()
        sleep(0.2)
    n.clear()
    n.show()
    del n
    exit(0)