XIAO Internal Pull-up Resistors

Hi MatthewM
I tried the code you wrote.
The D2 internal pull-up pinMode(2, INPUT_PULLUP); worked without any problem in my environment, windows 10 and Arduino 1.8.13.
I just made the following changes to avoid compile errors.
Serial.println(“xxxxxxxx”); ----> Serial.println(“xxxxxxxx”);
“” ----> “”


//MatthewM's code
//
int button = 0;
void setup()
{
Serial.begin(9600);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
//pinMode(3, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP); //**************** use D2
}

void loop()
{
//button = buttonRead(); //Button 0 = null, 1 = button D0, 2 = button D1, 3 = button D3
button = buttonRead(); //Button 0 = null, 1 = button D0, 2 = button D1, 3 = button D2 //**************** use D2
Serial.println(button);
button = 0;
}

uint8_t buttonRead()
{
//Serial.println(“Here”);
Serial.println("Here"); //**************** to avoid compile error: stray '\342' in program

while(1) //Wait for a button to be pressed
{
if(digitalRead(0) == LOW)
{
//Serial.println(“Button 1”);
Serial.println("Button 1"); //**************** to avoid compile error: stray '\342' in program
delay(100);
return 1;
break;
}
if(digitalRead(1) == LOW)
{
//Serial.println(“Button 2”);
Serial.println("Button 2"); //**************** to avoid compile error: stray '\342' in program
delay(100);
return 2;
break;
}
//if(digitalRead(3) == LOW)
if(digitalRead(2) == LOW) //**************** use D2
{
//Serial.println(“Button 3”);
Serial.println("Button 3"); //**************** to avoid compile error: stray '\342' in program
delay(100);
return 3;
break;
}
}
}