const int BUTTON_PIN = 10;
unsigned long buttonPressStartTime = 0;
bool buttonWasPressed = false;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // Assumes button connects pin to GND
Serial.begin(9600);
Serial.println("hi Mom!\n");
}
void loop() {
int buttonState = digitalRead(BUTTON_PIN);
unsigned long currentMillis = millis();
// --- BUTTON PRESS LOGIC ---
if (buttonState == LOW) { // Button is being pressed
if (!buttonWasPressed) {
Serial.println(" mouse down,");
buttonPressStartTime = currentMillis;
buttonWasPressed = true;
}
} else { // Button is released
if (buttonWasPressed) {
unsigned long pressDuration = currentMillis - buttonPressStartTime;
buttonWasPressed = false;
Serial.print(" mouse up after ");
Serial.println(pressDuration);
}
}
// delay(25); // poor man's debounce
}