*/
int button1 = 2; // pushbutton connected to digital pin 7
int button2 = 3;
int button3 = 4;
int button4 = 5; //submit button
int buttonPushCounter1 = 0;
int buttonPushCounter2 = 0;
int buttonPushCounter3 = 0;
int buttonState1 = 0; // current state of the button
int lastButtonState1 = 0;
int buttonState2 = 0; // current state of the button
int lastButtonState2 = 0;
int buttonState3 = 0; // current state of the button
int lastButtonState3 = 0;
int buttonState4 = 0; // current state of the button
int lastButtonState4 = 0;
char button1val = ‘1’; // pushbutton connected to digital pin 7
char button2val = ‘2’;
char button3val = ‘3’;
int password1 = 4;
int password2 = 2;
int password3 = 3;
int ledPinRed = 12; // LED connected to digital pin 13
int val = 0; // variable to store the read value
int count = 0; // Number of times tried
void setup() {
// declare the ledPins as an OUTPUT:
pinMode(ledPinRed, OUTPUT);
pinMode(button1, INPUT); // sets the digital pin as input
pinMode(button2, INPUT); // sets the digital pin as input
pinMode(button3, INPUT); // sets the digital pin as input
pinMode(button4, INPUT); // sets the digital pin as input
Serial.begin(9600);
}
void loop() {
buttonState1 = digitalRead(button1);
buttonState2 = digitalRead(button2);
buttonState3 = digitalRead(button3);
buttonState4 = digitalRead(button4);
// compare the buttonState to its previous state
if (buttonState1 != lastButtonState1) {
// if the state has changed, increment the counter
if (buttonState1 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter1++;
Serial.println(“on”);
Serial.print(“First Code: “);
Serial.println(
buttonPushCounter1, DEC);
}
else {
// if the current state is LOW then the button
// wend from on to off:
//Serial.println(“off”);
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState1 = buttonState1;
// compare the buttonState to its previous state
if (buttonState2 != lastButtonState2) {
// if the state has changed, increment the counter
if (buttonState2 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter2++;
//Serial.println(“on”);
Serial.print(“Second Code: “);
Serial.println(buttonPushCounter2, DEC);
}
else {
// if the current state is LOW then the button
// wend from on to off:
//Serial.println(“off”);
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState2 = buttonState2;
// compare the buttonState to its previous state
if (buttonState3 != lastButtonState3) {
// if the state has changed, increment the counter
if (buttonState3 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter3++;
// Serial.println(“on”);
Serial.print(“Third Code: “);
Serial.println(buttonPushCounter3, DEC);
}
else {
// if the current state is LOW then the button
// wend from on to off:
//Serial.println(“off”);
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState3 = buttonState3;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonState4 == LOW) {
if (buttonPushCounter1 == password1 && buttonPushCounter2 == password2 ){
Serial.println(” Password is correct”);
digitalWrite(ledPinRed, LOW);
}
else{
Serial.println(” Password is incorrect”);
digitalWrite(ledPinRed, HIGH);
}
}
/*
if (buttonPushCounter1 % 4 == 0) {
digitalWrite(ledPinRed, HIGH);
} else {
digitalWrite(ledPinRed, LOW);
}
*/