Skip to content

BlinkStick Pro: Display analogue clock on 16 LED ring

arvydas edited this page Sep 18, 2014 · 2 revisions

You will need an Adafruit NeoPixel ring for this example.

from datetime import datetime
import time
import math
import colorsys

from blinkstick import blinkstick

class Main(blinkstick.BlinkStickPro):
    def run(self):
        self.off()

        try:
            while (True):
                self.clear()
                t = datetime.now()

                hour = t.time().hour
                minute = t.time().minute
                second = t.time().second

                hour_pos = 15 - int((hour / 24.0) * 16)
                minute_pos = 15 - int((minute / 60.0) * 16)
                second_pos = 15 - int((second / 60.0) * 16)

                self.set_color_or(hour_pos, 255, 0, 0)
                self.set_color_or(minute_pos, 0, 255, 0)
                self.set_color_or(second_pos, 0, 0, 255)

                self.send_data_all()
                time.sleep(0.1)
        except KeyboardInterrupt:
            self.off()
            return


    def set_color_or(self, x, r, g, b):
        cr, cg, cb = self.get_color(0, x)
        self.set_color(0, x, int(r) | int(cr), int(g) | int(cg), int(b) | int(cb))

main = Main(r_led_count=16)

if main.connect():
    main.run()
else:
    print "No BlinkSticks found"

print "exit"