I am getting inconsistent readings on the inputs to the XIAO. Attaching the code. At first I had 3 buttons to DI0,1,2 and I was getting strange inputs that were being read on the serial monitor. I removed the three buttons and I am still getting strange readings. Not sure why the input turns to a value 1. There is nothing connected to any other inputs.
Any suggestions on what I can do? I am connecting the XIAO to the USB-C.
#define BUTTON_0 0
#define BUTTON_1 1
#define BUTTON_2 2
boolean buttonState_0;
boolean buttonState_1;
boolean buttonState_2;
void setup()
{
pinMode(BUTTON_0, INPUT);
pinMode(BUTTON_1, INPUT);
pinMode(BUTTON_2, INPUT);
pinMode (LED_BUILTIN,OUTPUT);
SerialUSB.begin(115200);
while (!SerialUSB) ;
}
//===========================================================
void loop()
{
buttonState_0 = digitalRead(BUTTON_0);
buttonState_1 = digitalRead(BUTTON_1);
buttonState_2 = digitalRead(BUTTON_2);
Serial.print(buttonState_0);
Serial.print(buttonState_1);
Serial.print(buttonState_2);
Serial.println ();
delay(500);
digitalWrite(LED_BUILTIN, buttonState_0);
digitalWrite(LED_BUILTIN, buttonState_1);
digitalWrite(LED_BUILTIN, buttonState_2);
}