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: EasyButton Control - Source Code NOT compiled for: Arduino Nano - Source Code created on: 2024-04-25 11:46:22 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Ensure LED diode turns on for 50ms after pressing */ /* the EasyButton. It should turn off after 50ms, */ /* even if the button is still pressed. Allow */ /* reactivation only after a 2s delay. Button is */ /* connected to pin 6, diode is connected to pin 7 */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
EasyButton button(6); // Button connected to pin 6 const uint8_t LED_PIN = 7; // LED diode connected to pin 7 bool buttonPressed = false; unsigned long buttonPressTime = 0; unsigned long lastDeactivationTime = 0; void setup() { pinMode(LED_PIN, OUTPUT); button.begin(); button.onPressed(onButtonPressed); } void loop() { button.read(); if (buttonPressed && millis() - buttonPressTime >= 50) { digitalWrite(LED_PIN, LOW); buttonPressed = false; lastDeactivationTime = millis(); } if (!buttonPressed && millis() - lastDeactivationTime >= 2000) { button.activate(); } } void onButtonPressed() { buttonPressTime = millis(); digitalWrite(LED_PIN, HIGH); buttonPressed = true; }
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)