/********* 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;
}