In this post, I showed how I made my Raspberry Pi jukebox. Here's how it is controlled.
At it's core, it's just a python script which waits for interrupts from the Pi's GPIO pins. That's the easy bit (although it would be a lot easier if there wasn't two different ways to number GPIO pins - I mean really...)
I do know that just making a bunch of functions isn't particularly pythonic and I should probably do something with classes and objects and stuff, but I had a really immovable deadline on this project so I just stuck with what I knew (which mostly comes from php, years ago).
Adafruit provide a library to let you access the Dotstar leds, but it's pretty basic. That's cool, it was fun learning how to figure stuff out. I ended up using a couple of modules to generate colour gradients and to shift between various colourspaces.
A nifty thing happened when I wanted to flash random, but bright colours as part of rave mode. Taking random RGB values was getting very pastel colours most of the time, which wasn't quite what I was looking for. A friend on Facebook suggested using HSV, so I could set saturation/value to a high value (70-100%) and then take a random hue. Worked wonderfully, but I couldn't ever get a decent video of it in action to show the difference.
I used threading (for the first time in python, yay!) to run a background thread that polls Kodi to see if it's playing, because Kodi can be controlled by means other than the buttons, so we need to know if it's playing to decide whether to put the lights on or not.
Some leds are "fixed" - they're the ones over the switches - and will remain a single colour while the rest of the strip phases colours. That lets you know which switch is on.
Ravemode is still my favourite bit. That was good fun to come up with.
Code is long so it's after the jump. I know it could be tidier, and a bit smarter, but I was on a deadline. I shall return to fiddle with it later on. There's more I'd like this box to do, but for now it just needs to play music.