Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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: Debounced Button - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2025-10-06 21:29:38 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* give example of button. */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /* Button example on Arduino UNO: - Button connected between pin 2 and GND - Internal pull-up resistor enabled via INPUT_PULLUP - LED on built-in pin 13 toggles on each press - Debouncing implemented for reliable presses */ // Pin assignments const int BUTTON_PIN = 2; const int LED_PIN = 13; // Debounce state int lastButtonState = HIGH; unsigned long lastDebounceTime = 0; const unsigned long DEBOUNCE_DELAY = 50; // milliseconds // LED state int ledState = LOW; void setup(void) { // Initialize serial for debugging (optional) Serial.begin(9600); // Initialize pins pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, ledState); Serial.println("Button example started. Press the button to toggle LED."); } void loop(void) { int reading = digitalRead(BUTTON_PIN); // If button state changed, reset debounce timer if (reading != lastButtonState) { lastDebounceTime = millis(); } // See if enough time has passed to debounce if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) { if (reading != lastButtonState) { lastButtonState = reading; // Button pressed (active LOW) if (reading == LOW) { ledState = !ledState; digitalWrite(LED_PIN, ledState ? HIGH : LOW); Serial.print("Button pressed. LED is now "); Serial.println(ledState ? "ON" : "OFF"); } } } } /* END CODE */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)