{"id":14646,"date":"2017-12-27T19:23:33","date_gmt":"2017-12-28T00:23:33","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=14646"},"modified":"2020-08-30T14:23:27","modified_gmt":"2020-08-30T18:23:27","slug":"circuit-playground-express-chord-guitar","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2017\/12\/27\/circuit-playground-express-chord-guitar\/","title":{"rendered":"Circuit Playground Express Chord Guitar"},"content":{"rendered":"\n<p class=\"has-accent-color has-text-color\"><strong>Hey! This doesn&#8217;t work any more, as CircuitPython changed and I haven&#8217;t found a way to update it with the new interpreter.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Circuit Playground Express Chord Guitar\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/lwbUNxSwCiw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Since there are seven touch pads on a <a href=\"https:\/\/www.adafruit.com\/product\/3333\">Circuit Playground Express<\/a>, that&#8217;s enough for traditional 3-chord (\u00e2\u2026\u00a0, \u00e2\u2026\u00a3, \u00e2\u2026\u00a4) songs in the keys of C, D and G. That leaves one pad extra for a \u00e2\u2026\u00a5<em><small>min<\/small><\/em> chord for so you can play <a href=\"https:\/\/www.youtube.com\/watch?v=wqMZv1DN1Gc\">Neutral Milk Hotel <\/a>songs in G, of course.<\/p>\n\n\n\n<p>CircuitPython source and samples: <a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/12\/cpx-chord_guitar.zip\">cpx-chord_guitar.zip<\/a>. Alternatively, on github: <a href=\"https:\/\/github.com\/scruss\/cpx_chord_guitar\/archive\/v1.0.zip\">v1.0<\/a> from <a href=\"https:\/\/github.com\/scruss\/cpx_chord_guitar\">scruss\/cpx_chord_guitar<\/a><\/p>\n\n\n\n<p>The code is really simple: poll the seven touch pads on the CPX, and if one of them is touched, play a sample and pause for a short time:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Circuit Playground Express Chord Guitar\n# scruss - 2017-12\n\n# these libraries should be installed by default in CircuitPython\nimport touchio\nimport board\nimport time\nimport neopixel\nimport digitalio\nimport audioio\n\n# touch pins, anticlockwise from battery connector\ntouch_pins= &#x5B;\n    touchio.TouchIn(board.A1),\n    touchio.TouchIn(board.A2),\n    touchio.TouchIn(board.A3),\n    touchio.TouchIn(board.A4),\n    touchio.TouchIn(board.A5),\n    touchio.TouchIn(board.A6),\n    touchio.TouchIn(board.A7)\n]\n\n# 16 kHz 16-bit mono audio files, in same order as pins\nchord_files = &#x5B;\n    \"chord-C.wav\",\n    \"chord-D.wav\",\n    \"chord-E.wav\",\n    \"chord-Em.wav\",\n    \"chord-F.wav\",\n    \"chord-G.wav\",\n    \"chord-A.wav\"\n]\n\n# nearest pixels to touch pads\nchord_pixels = &#x5B; 6, 8, 9, 0, 1, 3, 4 ]\n\n# set up neopixel access\npixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2)\npixels.fill((0, 0, 0))\npixels.show()\n\n# set up speaker output\nspeaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)\nspeaker_enable.switch_to_output(value=True)\n\n# poll touch pins\nwhile True:\n    for i in range(len(touch_pins)):\n        # if a pin is touched\n        if touch_pins&#x5B;i].value:\n            # set nearest pixel\n            pixels&#x5B;chord_pixels&#x5B;i]] = (0, 0x10, 0)\n            pixels.show()\n            # open and play corresponding file\n            f=open(chord_files&#x5B;i], \"rb\")\n            a = audioio.AudioOut(board.A0, f)\n            a.play()\n            # blank nearest pixel\n            pixels&#x5B;chord_pixels&#x5B;i]] = (0, 0, 0)\n            pixels.show()\n            # short delay to let chord sound\n            # might want to try this a little shorter for faster play\n            time.sleep(0.2)\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>This is <a href=\"http:\/\/scruss.com\/blog\/2017\/12\/19\/synthesizing-simple-chords-with-sox\/\">roughly how I synthesized the samples<\/a>, but I made them quieter (the MEMS speaker on the CPX went all buzzy at full volume, and not in a <a href=\"https:\/\/www.youtube.com\/watch?v=fBTT3VPriV8\">good way<\/a>) and added a bit of reverb. Here&#8217;s the sox command from the modified script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sox -n -r 16000 -b 16 \"chord-${chord}.wav\" synth 1 pl \"$first\" pl \"$third\" pl \"$fifth\" delay 0 .05 .1 remix - fade p 0 1 0.5 norm -5 reverb<\/pre>\n\n\n\n<p>Really, you do want to take a look at shortening the delay between the samples: you want it long enough for all of the notes of the chord to sound, but short enough that you can play faster songs. I came up with something that worked for me, kinda, and quickly; it&#8217;s worth fixing if you have the time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey! This doesn&#8217;t work any more, as CircuitPython changed and I haven&#8217;t found a way to update it with the new interpreter. Since there are seven touch pads on a Circuit Playground Express, that&#8217;s enough for traditional 3-chord (\u00e2\u2026\u00a0, \u00e2\u2026\u00a3, \u00e2\u2026\u00a4) songs in the keys of C, D and G. That leaves one pad extra [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Circuit Playground Express Chord Guitar #adabox006","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2],"tags":[3104,2896,3105,2903,3094,3106],"class_list":["post-14646","post","type-post","status-publish","format-standard","hentry","category-goatee-stroking-musing-or-something","tag-adabox006","tag-adafruit","tag-circuitpython","tag-guitar","tag-micropython","tag-synth"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-3Oe","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=14646"}],"version-history":[{"count":5,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14646\/revisions"}],"predecessor-version":[{"id":16453,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14646\/revisions\/16453"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=14646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=14646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=14646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}