Capacitive Touch Keyboard with MakeCode: Adafruit Circuit Playground Express

Updated 07 May 2018


On the lower left-hand portion of every Adafruit Circuit Playground Express, there is a small onboard speaker and class D amplifier. This allows you to make some pretty loud sounds! The amplifier is also connected to the true analog output on pin A0, which is marked with a wavy line symbol. You can turn off the speaker and only output through the pin if you like. For this tutorial, we are going to use the speaker and the capacitive touchpads to make a capacitive touch keyboard! 


Adafruit Circuit Playground Express Speaker and AmpAdafruit Circuit Playground Express Audio Out

There are seven capacitive touchpads on the Circuit Playground Express which means we have a pad for each note in a scale! You can either touch the pads directly or use alligator clips or jumpers to connect to any capacitive/conductive item you like. You can make the keys out of tools, fruit, or even liquid! I have used small amounts of copper tape connected with alligator clips. If you decide to connect to something with jumpers, be aware that allowing the wires to touch each other may give you false readings. Either route them in a way that none touch each other, or I found that if the wires are not moved after the board is powered up everything works even if they touch.

Adafruit Circuit Playground Express Capacitive Touchpads


The Code

Here is the complete program in MakeCode.

MakeCode Screenshot Capacitive Touch Keyboard

To make this sketch work properly we need to use while logic blocks. Each while loop contains one note and a light colour. While the capacitive pin is touched it runs the code within the respective while loop. The last note is played by touching both A3 and A2. For this to work properly we need to specify that A2 is played when only A2 is played and not with A3. On start, we initialize the volume and the brightness. We use the “pin X is pressed” input for capacitive touch sensing. If a pin is touched, then it outputs a unique sound and turns all the NeoPixels to a unique colour. If nothing is touched, then all sounds are stopped, and the lights are cleared.

Now you have a functional capacitive touch keyboard on your Circuit Playground Express. Try playing around with the code to make multiple tones play at once! Another element that you could add is some sharp/flat or minor notes by touching two keys at once. If you want to learn how to make the same project using CircuitPython, check out our Circuit Playground Tutorials!

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.