Here is the new code, and now it seems to work, at least the button thingy. I tried pushing the buttons and I recieved an output the way I wanted. But I seem to have done something wrong with the passcode. What have I missed? The only thing that happens even though I press button 1, 2, 3, 4 in order is that the red LED is turned on. It turns on when I plug in the Arduino board. What have I missed? (I don't have access to a camera right now, so I can't send you a picture of the board. All I did was adding a 100k ohm resistor between the cathode of the button and ground)
#include <Password.h>
const int key1 = 7;
const int key2 = 6;
const int key3 = 5;
const int key4 = 4;
int key1State;
int key2State;
int key3State;
int key4State;
const int greenLed = 3;
const int redLed = 2;
Password password = Password("1234");
void setup(){
Serial.begin(9600);
pinMode(key1, INPUT);
pinMode(key2, INPUT);
pinMode(key3, INPUT);
pinMode(key4, INPUT);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
}
void loop(){
key1State = digitalRead(key1);
if (key1State == HIGH) {
password.append('1');
Serial.println("1");
}
key2State = digitalRead(key2);
if (key2State == HIGH) {
password.append('2');
Serial.println("2");
}
key3State = digitalRead(key3);
if (key3State == HIGH) {
password.append('3');
Serial.println("3");
}
key4State = digitalRead(key4);
if (key4State == HIGH) {
password.append('4');
Serial.println("4");
}
if(password.evaluate())
{
// turn one led on and the other off
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
delay(500);
digitalWrite(greenLed, LOW);
password.reset();
}
else
{
// turn the other led on and the first one off
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
password.reset();
}
}
I am not from an English speaking country so forgive me if I spelled or wrote something wrong.