CCCPaste

Button LED rev_01

/********* 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: Button LED
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-03-04 22:51:19

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* led turns on for 0,5s after activating a button */
	/* and turns off even when the button is still active */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include  //https://github.com/evert-arias/EasyButton

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void onPressedForDuration();

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t przycisk_PushButton_PIN_D2 = 2;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t lampka_LED_PIN_D3 = 3;

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool lampka_LED_PIN_D3_rawData = 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float lampka_LED_PIN_D3_phyData = 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button(przycisk_PushButton_PIN_D2);

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(przycisk_PushButton_PIN_D2, INPUT_PULLUP);
  pinMode(lampka_LED_PIN_D3, OUTPUT);

  button.begin();
  button.onPressedFor(2000, onPressedForDuration);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  button.read(); // Continuously read the status of the button
  updateOutputs(); // Refresh output data
}

void updateOutputs()
{
  digitalWrite(lampka_LED_PIN_D3, lampka_LED_PIN_D3_rawData);
}

void onPressedForDuration()
{
  // Code to be executed when the button is pressed for the given duration.
  digitalWrite(lampka_LED_PIN_D3, HIGH); // Turn on the LED
  delay(500); // Keep the LED on for 0.5 seconds
  digitalWrite(lampka_LED_PIN_D3, LOW); // Turn off the LED
}