pleasedontcode

Button Toggle rev_02

Oct 25th, 2025
1,043
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: Button Toggle
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-10-25 17:21:09
  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.  
  29.  
  30. /* START CODE */
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. // GPIO definitions
  39. const int BUTTON_PIN = 0;
  40. const int LED_PIN = 2;
  41.  
  42.  
  43. void setup(void)
  44. {
  45.     // put your setup code here, to run once:
  46.     pinMode(BUTTON_PIN, INPUT_PULLUP);
  47.     pinMode(LED_PIN, OUTPUT);
  48.     // Ensure the LED is OFF initially
  49.     digitalWrite(LED_PIN, LOW);
  50. }
  51.  
  52.  
  53. void loop(void)
  54. {
  55.     // put your main code here, to run repeatedly:
  56.     int buttonState = digitalRead(BUTTON_PIN);
  57.     if (buttonState == LOW)
  58.     {
  59.         // Button pressed: turn LED ON
  60.         digitalWrite(LED_PIN, HIGH);
  61.     }
  62.     else
  63.     {
  64.         // Button released: turn LED OFF
  65.         digitalWrite(LED_PIN, LOW);
  66.     }
  67.     // Small delay for basic debouncing
  68.     delay(10);
  69. }
  70.  
  71. /* END CODE */
  72.  
Advertisement
Add Comment
Please, Sign In to add comment