Skip to content

Instantly share code, notes, and snippets.

@jemc
Created December 17, 2017 16:31
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 jemc/195a08b7dea2ba086862157b0bb8da07 to your computer and use it in GitHub Desktop.
Save jemc/195a08b7dea2ba086862157b0bb8da07 to your computer and use it in GitHub Desktop.
set -ex
# This script sets up a fresh Raspberry Pi 2 with Raspbian for the purposes
# of driving a string of color-changing LEDs to act as Christmas lights.
# I've written this out because it's common for the flash to get corrupted
# and have to start over fresh from recovery mode.
sudo apt-get remove wolfram-engine # way too huge and unnecessary
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install -y vim fish python-setuptools python-dev
git clone https://github.com/pimoroni/rpi_ws281x-python
rm -r rpi_ws281x-python/library/lib
git clone https://github.com/pimoroni/rpi_ws281x rpi_ws281x-python/library/lib
sed -i 's/-Werror -fPIC/-Werror -lrt -fPIC/' rpi_ws281x-python/library/Makefile
sed -i 's/libraries=\[/libraries=["rt", /' rpi_ws281x-python/library/setup.py
sh -c "cd rpi_ws281x-python/library && make"
sh -c "cd rpi_ws281x-python/library && sudo python setup.py install"
git clone https://github.com/pimoroni/unicorn-hat
sh -c "cd unicorn-hat/library/UnicornHat && sudo python setup.py install"
echo '#!/usr/bin/env python
import math
import time
import unicornhat as unicorn
unicorn.set_layout(unicorn.AUTO)
unicorn.rotation(0)
unicorn.brightness(1.0)
width,height=unicorn.get_shape()
i = 0.0
offset = 30
while True:
i = i + 0.1
for y in range(height):
for x in range(width):
r = 0
g = 0
r = (math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64.0 + 128.0
g = (math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64.0 + 128.0
b = (math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64.0 + 128.0
r = max(0, min(255, r + offset))
g = max(0, min(255, g + offset))
b = max(0, min(255, b + offset))
unicorn.set_pixel(x,y,int(g*0.85),int(r),int(b*0))
unicorn.show()
time.sleep(0.01)
' > ~/xmas-lights.py
chmod a+x ~/xmas-lights.py
sudo ~/xmas-lights.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment