I have recently developed two versions of the musical game Simon, where you ahve to remember a sequence of sounds/or lights and reneter them. Each time you get the sequence right it is increased in length.
Both use Sonic Pi 3 to both geerate teh game, and to play the sounds. In each case Sonic Pi is interfaced to an I/O unit using OSC messages. In the first case 4 LEDs and 4 push buttons are connected to the GPIO pins on a Raspberry Pi and an optional LDC character display displays your current score and the session hi-score. In the second the I/O is provided by an iPhone or iPad or android touch sensitive phone using the modestly priced app TouchOSC. YOu can see videos of the systems at
and at
links to the coce are at
OSChandlerwithscore.py
#!/usr/bin/env python3
#SPoschandler.py written by Robin Newman, July 2017 amended for this project Feb 2018
#Provides the "glue" to enable the GPIO on Raspberry Pi
#to communicate with Sonic Pi. Sonic Pi can control LEDs etc,and receive
#input from devices like push buttons connected to GPIO pins
#Sonic Pi can be running either on the Raspberry Pi,
#or on an external networked computer
#The program requires gpiod daemon to be running. Yu can install this with
#sudo apt-get update followed by sudo apt-get install pigpio if you don't have it
This file has been truncated. show original
Simon.rb
#Game of Simon for Sonic Pi, swtiches and leds and LCD display
#by Robin Newman, February 2018
use_osc 'localhost',8000
use_debug false
use_osc_logging false
use_random_seed(Time.now.nsec/10000)
osc "/led/control","o"
osc "/sendscores",0,0
This file has been truncated. show original
and
SimonTouchOSC.rb
#Game of Simon for Sonic Pi with TouchOSC interface
#by Robin Newman, February 2018
use_osc '192.168.1.240',9000 #address of TouchOSC device. Adjust to suit your setup
use_real_time
use_debug false
use_osc_logging false
osc "/touch/score",0 #intialise scores on TouchOSC device
osc "/touch/hiscore",0
sleep 0.2
set :button,"" #set up initial time state values
This file has been truncated. show original
index.xml
<?xml version="1.0" encoding="UTF-8"?><layout version="16" mode="0" orientation="horizontal"><tabpage name="dG91Y2g=" scalef="0.0" scalet="1.0" li_t="" li_c="gray" li_s="14" li_o="false" li_b="false" la_t="" la_c="gray" la_s="14" la_o="false" la_b="false" ><control name="cHVzaA==" x="57" y="145" w="200" h="200" color="gray" scalef="0.0" scalet="1.0" type="multipush" number_x="2" number_y="2" local_off="true" ></control><control name="c2NvcmU=" x="68" y="105" w="80" h="25" color="red" type="labelh" text="" size="14" background="true" outline="false" ></control><control name="aGlzY29yZQ==" x="160" y="106" w="80" h="25" color="red" type="labelh" text="" size="14" background="true" outline="false" ></control><control name="bGFiZWwz" x="40" y="47" w="239" h="24" color="yellow" type="labelh" text="U29uaWMgUGkgU2ltb24gR2FtZQ==" size="22" background="true" outline="false" ></control><control name="bGFiZWw0" x="69" y="78" w="80" h="25" color="red" type="labelh" text="U2NvcmU=" size="14" background="true" outline="false" ></control><control name="bGFiZWw1" x="159" y="76" w="80" h="25" color="green" type="labelh" text="SGktU2NvcmU=" size="14" background="true" outline="false" ></control><control name="bGFiZWw3" x="60" y="149" w="95" h="95" color="green" type="labelh" text="" size="14" background="true" outline="true" ></control><control name="bGFiZWw4" x="158" y="246" w="95" h="95" color="yellow" type="labelh" text="" size="14" background="true" outline="true" ></control><control name="bGFiZWw5" x="61" y="246" w="95" h="95" color="blue" type="labelh" text="" size="14" background="true" outline="true" ></control><control name="bGFiZWwxMA==" x="158" y="149" w="95" h="95" color="red" type="labelh" text="" size="14" background="true" outline="true" ></control><control name="bGVkZw==" x="61" y="150" w="93" h="93" color="green" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGVkeQ==" x="159" y="247" w="93" h="93" color="yellow" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGVkYg==" x="62" y="247" w="93" h="93" color="blue" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGVkcg==" x="159" y="150" w="93" h="93" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGFiZWwxMQ==" x="64" y="390" w="185" h="25" color="red" type="labelh" text="YnkgUm9iaW4gTmV3bWFu" size="14" background="true" outline="false" ></control><control name="dHVybg==" x="65" y="356" w="181" h="25" color="blue" type="labelh" text="" size="14" background="true" outline="true" ></control></tabpage></layout>
1 Like
I’ve just got this working on RPi3 and a n Android phone. Don’t forget to enable Receive remote OSC messages in the IO Prefs on Sonic pi.