Last active
August 29, 2015 14:20
-
-
Save adammhaile/457aa849f8690eb1f769 to your computer and use it in GitHub Desktop.
LEDCircle Demo with AllPixel and APA102 Disk from AdaFruit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bibliopixel import * | |
from bibliopixel.led import * | |
from bibliopixel.animation import BaseCircleAnim | |
class DiskBloom(BaseCircleAnim): | |
def __init__(self, led): | |
super(DiskBloom, self).__init__(led) | |
self._dir = dir | |
def step(self, amt = 8): | |
for i in range(self.ringCount): | |
c = colors.hue_helper(i, self.ringCount*2, self._step) | |
self._led.fillRing(i, c) | |
self._step += amt | |
if(self._step >= 255): | |
self._step = 0 | |
class ArcRotate(BaseCircleAnim): | |
def __init__(self, led, colors, arc = 180, outterRing = -1): | |
super(ArcRotate, self).__init__(led) | |
if outterRing < 0 or outterRing > self._led.lastRing: | |
outterRing = self._led.lastRing | |
self.outterRing = outterRing | |
self.colors = colors | |
self.arcCount = len(self.colors) | |
self.arc = arc/2 | |
def step(self, amt = 8): | |
led.all_off() | |
ci = 0 | |
for r in range(self.outterRing, self.outterRing - self.arcCount, -1): | |
c = self.colors[ci] | |
ci += 1 | |
self._led.fillRing(r, c, startAngle=self._step-self.arc, endAngle=self._step+self.arc) | |
self._step += amt | |
self._step %= 360 | |
import time | |
class ArcClock(BaseCircleAnim): | |
def __init__(self, led, secRing = -1, minRing = -1, hourRing = -1): | |
super(ArcClock, self).__init__(led) | |
self._internalDelay = 500 #only run twice per second | |
self.hourRing = hourRing | |
self.secRing = secRing | |
if self.secRing < 0: | |
self.secRing = self.lastRing | |
self.minRing = minRing | |
if self.minRing < 0: | |
self.minRing = self.lastRing - 1 | |
if self.hourRing < 0: | |
self.hourRing = self.lastRing - 2 | |
def step(self, amt = 1): | |
led.all_off() | |
t = time.localtime() | |
h = t.tm_hour | |
m = t.tm_min | |
s = t.tm_sec | |
self._led.fillRing(self.hourRing, colors.Red, startAngle=0, endAngle=(h%12)*(360/12)) | |
self._led.fillRing(self.minRing, colors.Green, startAngle=0, endAngle=m*(360/60)) | |
self._led.fillRing(self.secRing, colors.Blue, startAngle=0, endAngle=s*(360/60)) | |
rings = [ | |
[254,254], #0 - Center point | |
[248,253], #1 | |
[236,247], #2 | |
[216,235], #3 | |
[192,215], #4 | |
[164,191], #5 | |
[132,163], #6 | |
[92,131], #7 | |
[48,91], #8 | |
[0,47], #9 - Outer-most ring | |
] | |
if __name__ == '__main__': | |
import bibliopixel.log as log | |
log.setLogLevel(log.DEBUG) | |
from bibliopixel.drivers.serial_driver import * | |
import bibliopixel.gamma as gamma | |
driver = DriverSerial(LEDTYPE.APA102, 255, c_order=ChannelOrder.BGR, gamma=gamma.APA102, SPISpeed=12) | |
led = LEDCircle(driver, rings, threadedUpdate=False, rotation=0) | |
led.setMasterBrightness(64) | |
rainbow = [colors.Red, colors.Orange, colors.Yellow, colors.Green, colors.Blue, colors.Purple] | |
try: | |
while True: | |
anim = DiskBloom(led) | |
anim.run(amt=3, fps=30, max_steps=160) | |
anim = ArcRotate(led, colors = rainbow, arc=120, outterRing=-1) | |
anim.run(amt=15, fps=30, max_steps=180) | |
anim = ArcClock(led, secRing=-1, minRing=-1, hourRing=-1) | |
anim.run(max_steps=20) | |
except KeyboardInterrupt: | |
led.all_off() | |
led.update() | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment