pleasedontcode

LED Control rev_01

Nov 15th, 2025
195
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: LED Control
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-11-15 10:02:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Utilize the ESP32 DevKit V1's GPIO pins to control */
  21.     /* an onboard LED and read input from a connected */
  22.     /* push button, enabling basic user interaction. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25.  
  26. /* START CODE */
  27.  
  28. // Include the Arduino core library
  29. #include <Arduino.h>
  30.  
  31. // Define GPIO pins for onboard LED and push button
  32. const int onboardLedPin = 2; // Onboard LED pin for ESP32 DevKit V1
  33. const int pushButtonPin = 0; // Connected push button pin (change if different)
  34.  
  35. // Variable to store button state
  36. int buttonState = 0;
  37.  
  38. void setup() {
  39.   // Initialize serial communication at 115200 baud rate
  40.   Serial.begin(115200);
  41.  
  42.   // Initialize the onboard LED pin as output
  43.   pinMode(onboardLedPin, OUTPUT);
  44.   // Initialize the push button pin as input with internal pull-up resistor
  45.   pinMode(pushButtonPin, INPUT_PULLUP);
  46. }
  47.  
  48. void loop() {
  49.   // Read the state of the push button
  50.   buttonState = digitalRead(pushButtonPin);
  51.   // Check if button is pressed (active low)
  52.   if (buttonState == LOW) {
  53.     // Turn on the onboard LED
  54.     digitalWrite(onboardLedPin, HIGH);
  55.   } else {
  56.     // Turn off the onboard LED
  57.     digitalWrite(onboardLedPin, LOW);
  58.   }
  59.   // Small delay for debounce and stability
  60.   delay(10);
  61. }
  62.  
  63. /* END CODE */
  64.  
Advertisement
Add Comment
Please, Sign In to add comment