How to disable capacitive ipout for XIAO SAMD21

I’m just starting to dabble in Arduino so I’m testing a program that emulates a keyboard and will type a message when a button is shorted. However. Touching anything to the pins (a wire, a button, my finger) will trigger the input repeatedly. I have tried definign the pin on a non-QTouch pin, same result.

My sketch below if relevant.

#include <Keyboard.h>

const int buttonPin = 2;
int previousButtonState = HIGH;

void setup() {
  pinMode(buttonPin, INPUT);

void loop() {
  int currentButtonState = digitalRead(buttonPin);

  if (currentButtonState == LOW && previousButtonState == HIGH) {
    Keyboard.print("I am a button!");

  previousButtonState = currentButtonState;

Folks… I may have figured it out but I’m not sure why it’s working. Sharing my findings for future generations who are searching for answers.

I changed INPUT to INPUT_PULLUP. Is this really the best way to address this?

hi there,
Yes, the pullup internal resistor,Allows sinking of current or sourcing current albeit not allot. allows the input to be stable when connected or not.
Usually required when dealing with IO devices.
GL :slight_smile: PJ