/********* 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: 2023-12-29 08:25:55
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* if pushbutton P1 is switched ON then Output led */
/* will turn ON and remain ON, this output led status */
/* will be saved to EEPROM. And if pushbutton p2 is */
/* switched ON then output led will turn OFF and */
/* remain OFF. This will also save to EEPROM. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t P1_PushButton_PIN_D2 = 2;
const uint8_t P2_PushButton_PIN_D3 = 3;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t led_LED_PIN_D4 = 4;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button1(P1_PushButton_PIN_D2);
EasyButton button2(P2_PushButton_PIN_D3);
bool ledState = false; // Variable to store the state of the LED
void setup(void)
{
// put your setup code here, to run once:
pinMode(P1_PushButton_PIN_D2, INPUT_PULLUP);
pinMode(P2_PushButton_PIN_D3, INPUT_PULLUP);
pinMode(led_LED_PIN_D4, OUTPUT);
// Read the LED state from EEPROM
ledState = EEPROM.read(0);
// Set the initial state of the LED
digitalWrite(led_LED_PIN_D4, ledState);
// Set callback functions for button1 and button2
button1.onPressed([]() {
ledState = true;
digitalWrite(led_LED_PIN_D4, ledState);
EEPROM.write(0, ledState);
});
button2.onPressed([]() {
ledState = false;
digitalWrite(led_LED_PIN_D4, ledState);
EEPROM.write(0, ledState);
});
// Begin button interrupts
button1.begin();
button2.begin();
}
void loop(void)
{
// put your main code here, to run repeatedly:
// Update button states
button1.read();
button2.read();
}