/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: Button Setup - Source Code compiled for: Arduino Uno - Source Code created on: 2024-01-18 01:02:52 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* if button pressed, so print hello */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* if button pressed, so print hello */ /****** END SYSTEM REQUIREMENTS *****/ /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t butt_PushButton_PIN_D2 = 2; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button(butt_PushButton_PIN_D2); // Object of EasyButton class void setup(void) { // Initialize Serial communication Serial.begin(115200); Serial.println(); Serial.println(">>> EasyButton pressed example <<<"); // Set the push button pin as INPUT_PULLUP pinMode(butt_PushButton_PIN_D2, INPUT_PULLUP); // Attach a callback function to be called when the button is pressed button.onPressed([]() { Serial.println("Hello"); }) ; // Initialize the button button.begin(); } void loop(void) { // Read the button state bool buttonPressed = button.read(); // Check if button is pressed if(buttonPressed) { // Print "Hello" Serial.println("Hello"); // Add any additional actions based on the button press here } // Delay to allow other operations delay(10); }