Skip to content

Instantly share code, notes, and snippets.

@roblan
Last active December 4, 2017 21:29
Show Gist options
  • Save roblan/1a373b5a3414a464b53a140f55dab058 to your computer and use it in GitHub Desktop.
Save roblan/1a373b5a3414a464b53a140f55dab058 to your computer and use it in GitHub Desktop.
Pi VU Meter for 3D Xmas Tree
#!/usr/bin/env python
import pivumeter
from signal import pause
from gpiozero import LEDBoard
from time import sleep
from random import shuffle
MAX = 65535.0
class Xmas(pivumeter.OutputDevice):
def setup(self):
self.busy = False
self.tree = LEDBoard(*(2, 19,16,25,27,11, 17,4,8,5,26,13,9, 18,20,24,22,15,6,12, 23,10,14,7,21), pwm = True)
self.leds = [0] * 5
self.blink()
def normalize(self, number):
return max(float(format(number/MAX, '.1f')), 0.05)
def display(self):
self.busy = True
values = [self.leds[0]] + [self.leds[1]] * 5 + [self.leds[2]] * 7 + [self.leds[3]] * 7 + [self.leds[4]] * 5
self.tree.value = values
sleep(0.025)
self.busy = False
def display_fft(self, bins):
if self.busy: return
bins = bins[:(len(self.leds) - 1)];
self.leds = [self.leds[0]] + map(lambda x: self.normalize(x), bins);
def display_vu(self, left, right):
if self.busy: return
vu = left + right
self.leds[0] = self.normalize(vu)
if vu == 0:
if self.blinking != True:
self.blink()
else:
self.blinking = False
self.display()
def cleanup(self):
for led in reversed(self.tree.leds):
led.off()
sleep(0.1)
def blink(self):
self.blinking = True
leds = list(self.tree.leds[1:])
shuffle(leds)
self.tree[0].on()
for led in leds:
led.pulse()
sleep(0.05)
pivumeter.run(Xmas)
pause()
@roblan
Copy link
Author

roblan commented Nov 25, 2017

Pi VU Meter for 3D Xmas Tree

Small piece of software to blink leds in 3D Xmas Tree from The Pi Hut to the rythm of music.

How to

Install git and gpizero python library if you haven't already
sudo apt install git python-gpiozero
Follow this instructions to install Pi VU Meter: Python Front-end
(this should do the trick)

sudo apt install python-gpiozero
git clone -b devel https://github.com/pimoroni/pivumeter
cd pivumeter
setup.sh socket
cd ./python_server/library
sudo python setup.py install

Download this file (preferably in some other directory, so do eg. cd ~ first)

wget https://gist.github.com/roblan/1a373b5a3414a464b53a140f55dab058/raw/0406ff9b751ef4dca28697af7e2614bdc18e8591/xmastree.py

Run it
python ./xmastree.py

Play some music & enjoy :)

@Sponkenberg
Copy link

Hi!

Sorry but I need som help; I'm almost a complete newbie in programming but I'm eager to learn...

What steps do I need to perform to get this working on my 3DXmas tree? The error message I receive is: ImportError: No module named 'pivumeter'

If you could spare me some of your time I appreciate your efforts! Thanks in advance!

@roblan
Copy link
Author

roblan commented Dec 4, 2017

@Sponkenberg You have to install pivumeter (and gpiozero) first :)

sudo apt install python-gpiozero
git clone -b devel https://github.com/pimoroni/pivumeter
cd pivumeter
setup.sh socket
cd ./python_server/library
sudo python setup.py install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment