So I'm making a booth for school where you have to press a sequence on 4 buttons to get into it. I modified some code to use 4 buttons instead of 9. but I don't know how to have a longer password than 3 digits and I want to have say 5 leds that light up as you press the right button but if you mess up the leds reset. how difficult would this be for a beginner programmer
// How to Make an Arduino Keypad Lock
// Jlaservideo.com
#include <Servo.h>
#include <Keypad.h>
Servo ServoMotor;
char* password = "514"; // change the password here, just pick any 3 numbers
int position = 0;
int one = 0;
int two = 0;
int three = 0;
const byte ROWS = 2;
const byte COLS = 2;
char keys[ROWS][COLS] = {
{'1','2'},
{'4','5'},
};
byte rowPins[ROWS] = { 2, 3, };
byte colPins[COLS] = { 4, 5, };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int RedpinLock = 12;
int GreenpinUnlock = 13;
void setup()
{
pinMode(RedpinLock, OUTPUT);
pinMode(GreenpinUnlock, OUTPUT);
ServoMotor.attach(11);
LockedPosition(true);
}
void loop()
{
char key = keypad.getKey();
if (key == '*' || key == '#')
{
position = 0;
LockedPosition(true);
}
if (key == password[position])
{
position ++;
}
if (position == 3)
{
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked)
{
digitalWrite(RedpinLock, HIGH);
digitalWrite(GreenpinUnlock, LOW);
ServoMotor.write(11);
}
else
{
digitalWrite(RedpinLock, LOW);
digitalWrite(GreenpinUnlock, HIGH);
ServoMotor.write(90);
}
}