/********* 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 Toggle
- Source Code compiled for: Arduino Nano
- Source Code created on: 2024-03-16 19:55:32
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* The button should turned on and off on one click */
/****** SYSTEM REQUIREMENT 2 *****/
/* The button should turned on and off on one click */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/evert-arias/EasyButton
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void button1Pressed();
void button2Pressed();
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Please_PushButton_PIN_D2 = 2;
const uint8_t Please_PushButton_PIN_D3 = 3;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button1(Please_PushButton_PIN_D2);
EasyButton button2(Please_PushButton_PIN_D3);
bool button1State = false;
bool button2State = false;
void setup(void)
{
// put your setup code here, to run once:
pinMode(Please_PushButton_PIN_D2, INPUT_PULLUP);
pinMode(Please_PushButton_PIN_D3, INPUT_PULLUP);
button1.begin();
button2.begin();
button1.onPressed(button1Pressed);
button2.onPressed(button2Pressed);
}
void loop(void)
{
// put your main code here, to run repeatedly:
button1.read();
button2.read();
}
void button1Pressed()
{
button1State = !button1State;
if (button1State) {
// Turn on the button 1 functionality
Serial.println("Button 1 turned ON");
// Add your code to turn on the button 1 functionality here
} else {
// Turn off the button 1 functionality
Serial.println("Button 1 turned OFF");
// Add your code to turn off the button 1 functionality here
}
}
void button2Pressed()
{
button2State = !button2State;
if (button2State) {
// Turn on the button 2 functionality
Serial.println("Button 2 turned ON");
// Add your code to turn on the button 2 functionality here
} else {
// Turn off the button 2 functionality
Serial.println("Button 2 turned OFF");
// Add your code to turn off the button 2 functionality here
}
}