Fibre Optic Christmas Tree upgrade


#1

Hi all

I had a cheap table top fibre optic christmas tree with R G B LEDs in the base, which stopped working during Christmas. I had been wondering what to do with my Unicorn Hat 8X8 RGB display, so it was great for it to come to the rescue. I modified one of the Pimoroni sample Python scripts to only light the central ones to keep the light under the fibre optics, and produce better colour patterns. A wifi dongle lets me play with the tree remotely using SSH. Most of the sample scripts produce nice lights on the tree. Next phase will be to substitute a PiZero for the B+ so I can leave it as a permanent project. There is one minor problem which someone might be able to help with - I am running the code in the background with a “&” at the end of the call. I find that after a few hours of operation, the wifi dongle stops working, so I can’t SSH into it again, until I remove the dongle and plug it in again - then all is OK without upsetting the tree lights.
BTW - it looks like the link to Dropbox is not allowing the video to be shown - anybody know how to make it work? So I have just uploaded a static picture for now.

Tony

Here is a video link to the tree working, and the code is below (based on rainbow_blinky.py):

#!/usr/bin/env python
import unicornhat as unicorn
import time, colorsys
import numpy as np
import random as rnd
unicorn.brightness(0.5)
def make_gaussian(fwhm):
x = np.arange(0, 8, 1, float)
y = x[:, np.newaxis]
x0, y0 = 3.5, 3.5
fwhm = fwhm
gauss = np.exp(-4 * np.log(2) * ((x - x0) ** 2 + (y - y0) ** 2) / fwhm ** 2)
return gauss

while True:
h3 = rnd.random()
h1 = rnd.random()
h2 = rnd.random()
h4 = rnd.random()
h5 = rnd.random()
for z in range(600, 1400):

print z

	try: fwhm = 5.0/((z-1000)/100.0)
	except: fwhm = 500
	gauss = make_gaussian(fwhm)
	for y in range(2,6):
		for x in range(2,6):
			#h = 1.0/(x + y + 1.0)
			h = h3
			if x == 4 and y == 3: h = h1
			if x == 3 and y == 3: h = h2
			if x == 4 and y == 4: h = h4
			if x == 3 and y == 4: h = h5
			s = 0.8
			v = gauss[x,y]
			rgb = colorsys.hsv_to_rgb(h, s, v)
			r = int(rgb[0]*255.0)
			g = int(rgb[1]*255.0)
			b = int(rgb[2]*255.0)
			unicorn.set_pixel(x, y, r, g, b)
	unicorn.show()
	time.sleep(0.005)