const int buttonPin = 1; // the number of the pushbutton pin
uint8_t buttonState = 0; // variable for reading the pushbutton status
uint8_t oldState = 0; // variable for previous reading
void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("=== " __FILE__);
// initialize the LED pin as an output:
pinMode(LED_BUILTIN, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP); // push button released= HIGH
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin); // inverted logic
// check if the pushbutton is pressed. If it is, the buttonState is LOW:
if (buttonState != oldState)
{
Serial.print(millis());
Serial.print(":\t");
if (buttonState == LOW)
{
// turn LED on:
Serial.println("Button pressed");
digitalWrite(LED_BUILTIN, LOW); // inverted logic
}
else
{
// turn LED off:
Serial.println("Button released");
digitalWrite(LED_BUILTIN, HIGH); // inverted logic
}
oldState = buttonState;
}
}
I am curious if anyone else is having a problem powering the expansion board and Xiao with just the lipo? I the expansion board setup and working fine with USB and it continues to work on the lipo after unplugging the USB. WIth unit running on battery, once it is shut off with the power switch it will not turn on by the switch until I plug in the USB.