Skip to content

Instantly share code, notes, and snippets.

@chrisy
Created December 5, 2016 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisy/edf2b64ba17ea20425213bd54b8ba643 to your computer and use it in GitHub Desktop.
Save chrisy/edf2b64ba17ea20425213bd54b8ba643 to your computer and use it in GitHub Desktop.
tardis
#!/usr/bin/env python
import spidev
import time
import math
speed = 1000000
bpw = 8
spi = spidev.SpiDev()
spi.open(0,0)
spi.bits_per_word = bpw
spi.lsbfirst = False
spi.mode = 0
spi.max_speed_hz = speed
count = 250
limit = math.pi * 2.0
incr = math.pi / 64
step = 0
fadeat = 100
faderange = 60.0
fadeback = 300.0
fadecount = 0
fadeamount = 1.0
while True:
p = []
for i in range(count):
if i < count * 0.98:
p.append(0)
p.append(0)
p.append(int(fadeamount * 255.0))
else:
v = int((math.sin(step) + 1) * 127.0 * fadeamount)
p.append(v)
p.append(v)
p.append(v)
spi.xfer2(p, speed, 500, bpw)
step += incr
if step > limit:
step = 0
fadecount += 1
if fadecount > fadeat:
fadeamount = 1.0 - ((fadecount - fadeat) / faderange)
if fadeamount < 0.0:
fadeamount = 0.0
if fadecount > fadeback:
fadeamount = (fadecount - fadeback) / faderange
if fadeamount > 1.0:
fadeamount = 1.0
fadecount = 0
time.sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment