Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: LED Control
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-11-15 10:02:29
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Utilize the ESP32 DevKit V1's GPIO pins to control */
- /* an onboard LED and read input from a connected */
- /* push button, enabling basic user interaction. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- // Include the Arduino core library
- #include <Arduino.h>
- // Define GPIO pins for onboard LED and push button
- const int onboardLedPin = 2; // Onboard LED pin for ESP32 DevKit V1
- const int pushButtonPin = 0; // Connected push button pin (change if different)
- // Variable to store button state
- int buttonState = 0;
- void setup() {
- // Initialize serial communication at 115200 baud rate
- Serial.begin(115200);
- // Initialize the onboard LED pin as output
- pinMode(onboardLedPin, OUTPUT);
- // Initialize the push button pin as input with internal pull-up resistor
- pinMode(pushButtonPin, INPUT_PULLUP);
- }
- void loop() {
- // Read the state of the push button
- buttonState = digitalRead(pushButtonPin);
- // Check if button is pressed (active low)
- if (buttonState == LOW) {
- // Turn on the onboard LED
- digitalWrite(onboardLedPin, HIGH);
- } else {
- // Turn off the onboard LED
- digitalWrite(onboardLedPin, LOW);
- }
- // Small delay for debounce and stability
- delay(10);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment