pleasedontcode

Debounced Button rev_01

Oct 25th, 2025
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Debounced Button
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-10-25 16:39:57
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Define a user requirement for continuously */
  21.     /* monitoring a push button on GPIO0 to turn an */
  22.     /* onboard LED on GPIO2 on press and off on release, */
  23.     /* utilizing GPIO functionalities of the connected */
  24.     /* components. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. // GPIO definitions
  37. const int BUTTON_PIN = 0;
  38. const int LED_PIN = 2;
  39.  
  40.  
  41. void setup(void)
  42. {
  43.     // put your setup code here, to run once:
  44.     pinMode(BUTTON_PIN, INPUT_PULLUP);
  45.     pinMode(LED_PIN, OUTPUT);
  46.     // Ensure the LED is OFF initially
  47.     digitalWrite(LED_PIN, LOW);
  48. }
  49.  
  50.  
  51. void loop(void)
  52. {
  53.     // put your main code here, to run repeatedly:
  54.     int buttonState = digitalRead(BUTTON_PIN);
  55.     if (buttonState == LOW)
  56.     {
  57.         // Button pressed: turn LED ON
  58.         digitalWrite(LED_PIN, HIGH);
  59.     }
  60.     else
  61.     {
  62.         // Button released: turn LED OFF
  63.         digitalWrite(LED_PIN, LOW);
  64.     }
  65.     // Small delay for basic debouncing
  66.     delay(10);
  67. }
  68.  
  69. /* END CODE */
  70.  
Advertisement
Add Comment
Please, Sign In to add comment