In this next step, we'll replace the buttons with capacitive touch. That way we don't have to click the button, just tap the pads with our fingertips

All that's needed is to replace the button checks with checks for the capacitive touch inputs. The code uses the top touch pad on each side as a replacement for the button on that side. 

Touch sensitivity can be adjusted to suit your need. See the code for the use of adjust_touch_threshold

As before, save the code below as on your Circuit Playground Express.

# SPDX-FileCopyrightText: 2018 Dave Astels for Adafruit Industries
# SPDX-License-Identifier: MIT

Circuit Playground Express GBoard: capacitive touch generating tones

Adafruit invests time and resources providing this open source code.
Please support Adafruit and open source hardware by purchasing
products from Adafruit!

Written by Dave Astels for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.

All text above must be included in any redistribution.

import time
from import cpx


# You can adjust this to get the level of sensitivity you want.

while True:
    if cpx.touch_A4:
        cpx.play_tone(4000, DOT_DURATION)
        while cpx.touch_A4:
    elif cpx.touch_A3:
        cpx.play_tone(4000, DASH_DURATION)
        while cpx.touch_A3:

Now, when you touch the A4 pad a short tone will sound, and when you touch the A3 pad a longer tone will sound.  As before, the while cpx.touch_X: pass code causes it to wait until you release the button before playing the tone again. This prevents you triggering it multiple times accidentally.

Be careful how you hold the board so that you don't accidentally touch the A3 and A4 touch pads.

This guide was first published on Jul 24, 2018. It was last updated on Jun 15, 2024.

This page (Adding Touch) was last updated on Jun 15, 2024.

Text editor powered by tinymce.