/********* 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 Sequence
- Source Code compiled for: Arduino Uno
- Source Code created on: 2024-03-02 15:51:19
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* I have regular push buttons on pins 2 to 10 and a */
/* light on 11 of my arduino uno. Create a code so */
/* that you can use the buttons as a password, so the */
/* password is pin 2, 3, 4, and 10. If you press them */
/* one after the other, the light will come on. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/evert-arias/EasyButton
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t button_PushButton_PIN_D2 = 2;
const uint8_t button_PushButton_PIN_D3 = 3;
const uint8_t button_PushButton_PIN_D4 = 4;
const uint8_t button_PushButton_PIN_D10 = 10;
const uint8_t light_PIN_D11 = 11;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button_D2(button_PushButton_PIN_D2);
EasyButton button_D3(button_PushButton_PIN_D3);
EasyButton button_D4(button_PushButton_PIN_D4);
EasyButton button_D10(button_PushButton_PIN_D10);
bool isPasswordCorrect = false;
bool button_D2_Pressed = false;
bool button_D3_Pressed = false;
bool button_D4_Pressed = false;
bool button_D10_Pressed = false;
void setup(void)
{
// put your setup code here, to run once:
pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
pinMode(button_PushButton_PIN_D3, INPUT_PULLUP);
pinMode(button_PushButton_PIN_D4, INPUT_PULLUP);
pinMode(button_PushButton_PIN_D10, INPUT_PULLUP);
pinMode(light_PIN_D11, OUTPUT);
// Initialize the buttons
button_D2.begin();
button_D3.begin();
button_D4.begin();
button_D10.begin();
}
void loop(void)
{
// put your main code here, to run repeatedly:
// Read the state of the buttons
button_D2.read();
button_D3.read();
button_D4.read();
button_D10.read();
// Check if button D2 is pressed
if (button_D2.isPressed())
{
button_D2_Pressed = true;
}
// Check the sequence of button presses
if (button_D2_Pressed)
{
if (button_D3.isPressed())
{
button_D3_Pressed = true;
}
if (button_D3_Pressed && button_D4.isPressed())
{
button_D4_Pressed = true;
}
if (button_D4_Pressed && button_D10.isPressed())
{
button_D10_Pressed = true;
}
}
// Check if the password is entered correctly
if (button_D10_Pressed)
{
isPasswordCorrect = true;
}
// Turn on the light if the password is correct
if (isPasswordCorrect)
{
digitalWrite(light_PIN_D11, HIGH);
}
}