Learn
Circuit Playground: Part 2
Capacitive Touch

But what happens when we have more than two sounds? Two buttons is simply not enough for the cool things that we want to do.

Well, we are in luck. Circuit Playground Express comes with multiple capacitive touch sensors.

This quick-start example shows how you can read the capacitive touch sensors built into SEVEN of the Circuit Playground Express pads (pad A0 is not a capacitive touch pad).

Cap Touches

Pads A1-A7 can be used as capacitive devices and to access them, we can use:

  • cpx.touch_A1
  • cpx.touch_A2
  • cpx.touch_A3
  • cpx.touch_A4
  • cpx.touch_A5
  • cpx.touch_A6
  • cpx.touch_A7

In this exercise, we are going to add some code to the while loop so that there will be a musical note for each touch sensor.

Instructions

1.

Inside the while loop, we are going to add some if statements.

If cpx.touch_A1 is touched:

  • Play the frequency 262 for 0.5 second.
2.

If cpx.touch_A2 is touched:

  • Play the frequency 294 for 0.5 second.

If cpx.touch_A3 is touched:

  • Play the frequency 330 for 0.5 second.

If cpx.touch_A4 is touched:

  • Play the frequency 349 for 0.5 second.
3.

Click the Download button to download the code.py file.

Drag and drop the downloaded file into the CIRCUITPY drive on your computer.

Touch the A1, A2, A3, A4 pads.

Note: No extra hardware is required, you can touch the pads directly, but you may want to attach alligator clips or foil tape to metallic or conductive objects. Try silverware, fruit or other food, liquid, aluminum foil, and items around your desk!

Folder Icon

Sign up to start coding

Already have an account?