Skip to content

Instantly share code, notes, and snippets.

@mcoms
Created May 6, 2015 22:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcoms/4fd9a7349dd9715161ab to your computer and use it in GitHub Desktop.
Save mcoms/4fd9a7349dd9715161ab to your computer and use it in GitHub Desktop.
Fruit Piano prototype with MPR121, Arduino and Sonic Pi
source 'https://rubygems.org'
gem 'osc-ruby', '1.1.1'
gem 'serialport'
require 'bundler'
Bundler.require
# OSC client to communicate with Sonic Pi (which must be running)
client = OSC::Client.new 'localhost', 4557
# Set your arduino serial port here...
port_str = '/dev/tty.usbserial'
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new port_str, baud_rate, data_bits, stop_bits, parity
while true do
while (i = sp.gets.chomp) do
if i == 'pin 3 was just touched'
puts 'Banana'
client.send OSC::Message.new('/run-code', 'play chord(:C4, :major)')
elsif i == 'pin 6 was just touched'
puts 'Potato'
client.send OSC::Message.new('/run-code', 'play chord(:F4, :major)')
elsif i == 'pin 9 was just touched'
puts 'Apple'
client.send OSC::Message.new('/run-code', 'play chord(:G4, :major)')
end
end
end
sp.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment