CPE unable to detect multiple touches?

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
craigasanford
 
Posts: 8
Joined: Wed Oct 31, 2018 3:11 pm

CPE unable to detect multiple touches?

Post by craigasanford »

Hello,
I have a Circuit Playground Express that I'm using for a project. Should be a pretty simple thing - I have 6 screws in a 3d printed Star Wars Holocron that are run to A1-A6 on the board. If it detects all 6 are currently touched it will light up after a few seconds.

The issue I'm having is that it doesn't reliably detect all the touches every check (I have a 0.1 debounce). In fact, when I have all 6 touched sometimes I only see 1 or maybe 2 being touched (see code below for how I'm outputting which are touched). I've even implemented a count of how many are touched and made allowances so that if it miss detects 1 of the pads it'll still count - but even that isn't reliable.

Am I missing something obvious? If I only touch one at a time it outputs the correct pad number. And I've dropped the sensitivity very low. I would LOVE any suggestions!

Code: Select all

import time
from adafruit_circuitplayground.express import cpx

cpx.adjust_touch_threshold(1)

RED = (90, 0, 0)
BLACK = (0, 0, 0)
vals = (
0,    1,    2,    3,    4,    5,    7,    9,    12,
15,    18,    22,    27,    32,    38,    44,    51,    58,
67,    76,    86,    96,    108,    120,    134,    148,    163,
180,    197,    216,    235,    255
 )

FADE_DURATION = 3
FADE_STEP_DURATION = FADE_DURATION / len(vals)
cpx.pixels.fill(RED)
cpx.pixels.brightness = 0  # set brightness value

holdDuration = 10
curBrightness = 0
curStep = 0
touched = False
COMPLETE = False

TOTALTOUCHES = 0
STRING = ""

while True:
     if not COMPLETE:
        TOTALTOUCHES = 0
        STRING = ""
        if cpx.touch_A1:
            TOTALTOUCHES += 1
            STRING += "1 "
        if cpx.touch_A2:
            TOTALTOUCHES += 1
            STRING += "2 "
        if cpx.touch_A3:
            TOTALTOUCHES += 1
            STRING += "3 "
        if cpx.touch_A4:
            TOTALTOUCHES += 1
            STRING += "4 "
        if cpx.touch_A5:
            TOTALTOUCHES += 1
            STRING += "5 "
        if cpx.touch_A6:
            TOTALTOUCHES += 1
            STRING += "6 "
        now = time.monotonic()
        print(STRING)
        if TOTALTOUCHES >= 5:
            print("pass")
            if touched is False:
                touchStartTime = time.monotonic()
                touched = True
                cpx.pixels.fill(RED)
            if now - touchStartTime > holdDuration and touched is True:
                if curBrightness < 1:
                    curStep += 1
                    curBrightness = vals[curStep] / 255
                    # print(curBrightness)
                    cpx.pixels.brightness = curBrightness
                    time.sleep(FADE_STEP_DURATION)
                if curBrightness >= 1:
                    cpx.play_file("test.wav")
                    cpx.pixels.fill(RED)
                    cpx.pixels.brightness = 1
                    COMPLETE = True
            time.sleep(0.1)
        else:
            touched = False
            curBrightness = 0
            curStep = 0
            cpx.pixels.brightness = curBrightness
            cpx.pixels.fill(BLACK)
            # print(now)
            time.sleep(0.1)

Locked
Please be positive and constructive with your questions and comments.

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”