# Makey Makey Ukulele w/ Sonic Pi key presses

**URL:** <https://in-thread.sonic-pi.net/t/makey-makey-ukulele-w-sonic-pi-key-presses/4484>\
**Category:** Creations & Ideas\
**Created:** [October 10, 2020, 2:46am UTC](https://in-thread.sonic-pi.net/t/makey-makey-ukulele-w-sonic-pi-key-presses/4484 "2020-10-10T02:46:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrbombmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mrbombmusic/32/2282_2.png) [@mrbombmusic](https://in-thread.sonic-pi.net/u/mrbombmusic)\
**Post date:** [October 10, 2020, 2:46am UTC](https://in-thread.sonic-pi.net/t/makey-makey-ukulele-w-sonic-pi-key-presses/4484/1 "2020-10-10T02:46:25Z")

</div>

After reading [this thread](https://in-thread.sonic-pi.net/t/revised-computer-keyboard-note-input-for-sonic-pi/1818) I adapted the code to hooked up my Makey Makey to my old cardboard ukulele and strum some chords.

4 key presses are hooked up to the Ukulele strings via the Makey Makey and then you can change the chord by pressing different keys on the keyboard (which I may make a foot switch board to trigger via the Makey Makey as well)

[![](https://img.youtube.com/vi/ctDR8-nkZYw/hqdefault.jpg "Makey Makey Ukulele w/ Sonic Pi") ](https://www.youtube.com/watch?v=ctDR8-nkZYw)

Here’s the adapted code (prob could be cleaner 🤷🏼‍♂️ )  
Big thanks to @robin.newman . This is a game changer for me!

```ruby
notes=Hash.new
chords=Hash.new

l=[[:g4,:c4, :e4, :c5],
   [:g4,:d4, :g4, :b4],
   [:a4,:d4, :fs4, :a4],
   [:a4,:c4, :e4, :a4],
   [:a4,:c4, :f4, :a4]
   ]

n=["a", "w", "s", "d", "f"] 
c=["g", "h", "j", "k"]
set :n,n
l.length.times do |i| #loop to create the hash
  notes[n[i].ord]=l[i]
  
end
c.length.times do |i|
  chords[c[i].ord]=i
end

k = 0
k2 = 0
live_loop :getkey do
  use_real_time
  use_synth :pluck
  b= sync "/osc*/key"
  if b[0] == 103 || b[0] == 104 || b[0] == 106 || b[0] == 107
    m = b[0]
    k2 = k
  else
    k=b[0]
  end 
  
  #note to play
  if b[0] == 103 || b[0] == 104 || b[0] == 106 || b[0] == 107
    play notes[k2.to_i][chords[m.to_i]]
  end
  sleep 0.05
end

```
