Three years ago at Christmas 1974 I produced a medley of carols for Sonic Pi. During the last week I acquired one of the PiHut Christmas Trees, which gave me a good test of my soldering skills in assembling it. Having built it, I thought that it would be nice to get Sonic Pi to control it, and to get the lights to flash in time to the carol pieces. This was similar to other projects I had previously done, and I wrote a small python OSC server to which Sonic Pi 3 could be a client, sending OSC messages which the server could receive and act upon. I incorporated the gpiozero library, making it fairly easy to control the leds. I incorporated the code that The PiHut published with the tree, and also some code in the comments about the tree on their site by user “DJ” which I modified so that I could separately contol different zones of the Christmas tree. This let me drive it with up to four different tune parts, with each part controlling a subsection of the leds.
On Sonic Pi, relatively small modifications had to be made to the original code. I added a function flash which could send an OSC message to the server with a numeric parameter in the range 0 to 8. This selected which leds were affected and in most cases caused these to flash once on then off. flash(8) strated the shimmering pattern in the original PiHut code, and flash(0) turned all the leds off. I added calls to this flash function in the routine which played the sequence of notes, which was used by all the playing sections, and added an input paramter to it to control the flash parameter to be sent.
Both the python server and the Sonic Pi program were run on the same Raspberry Pi 3, although I also made a version where the server was on a pizero and the Sonic Pi program was running on a separate Mac computer. This merely involved a change in each of the server and sonic pi programs to specify the actual IP addresses of each machine, which had to be linked by a network.
code is at https://gist.github.com/rbnpi/5f5e9356e627d1cbc52086efbb56456c