// made with ChatGBT // Pin connected to the button const int buttonPin = 8; // Variable to store the previous button state int prevButtonState = HIGH; void setup() { // Initialize serial communication Serial.begin(9600); // Set button pin as input pinMode(buttonPin, INPUT_PULLUP); } void loop() { // Read the state of the button int buttonState = digitalRead(buttonPin); // Check if the button is pressed if (buttonState == LOW && prevButtonState == HIGH) { Serial.println("Button pressed!"); } // Send a serial code while the button is not pressed if (buttonState == HIGH) { Serial.println("b"); } prevButtonState = buttonState; }