Its a combination lock and then some- Niki Selken

The Project I made was a combination lock. Also, I made my own LED light pattern in arduino code. The code works like this:

1. When you press button 1 five times the green LED flashes 5 times

2. When you press button 2 four times the green LED flashes 4 times

3. When you press button 3 three times, the red LED flashes 3 times

4. When you press button 4 two times, the red LED flashes 2 times

IMG_2645 IMG_2644

Here is the code:

int led = 2; //LED connect to digital pin 2
int red = 8; //LED connect to digital pin 8
int PushButton = 3; //pushbbutton connected to digital pin 3
int PushButton2 = 4; //pushbbutton connected to digital pin 4
int PushButton3 = 5; //pushbbutton connected to digital pin 5
int PushButton4 = 6; //pushbbutton connected to digital pin 6
int debounce = 10; //Length of time to debounce switch in milliseconds
int ButtonValue2; //used to feel cutrrent state of button
int ButtonValue3; //used to feel cutrrent state of button
int ButtonValue4; //used to feel cutrrent state of button
int ButtonValue; //used to feel cutrrent state of button

int ButtonCount = 0;
int ButtonCount2 = 0;
int ButtonCount3 = 0;
int ButtonCount4 = 0;

int LastButtonValue = LOW;
int LastButtonValue2 = LOW;
int LastButtonValue3 = LOW;
int LastButtonValue4 = LOW;
void setup()
{

pinMode(led, OUTPUT);
pinMode(red, OUTPUT);
pinMode(PushButton, INPUT);
pinMode(PushButton2, INPUT);
pinMode(PushButton3, INPUT);
pinMode(PushButton4, INPUT);
Serial.begin(9600);
Serial.println(“Blink”);

}

void loop()
{

ButtonValue = digitalRead(PushButton);
if(ButtonValue != LastButtonValue){
delay(debounce); //DOuble check the press – is it real?
ButtonValue = digitalRead(PushButton);
if(ButtonValue == HIGH && LastButtonValue == LOW){

ButtonCount++; //add 1 to the Buttoncounter variable
Serial.println(ButtonCount);
if (ButtonCount>=5){ //if we count to five flash led twice
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
delay (200);
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
delay (200);
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
delay (200);
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
delay (200);
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
ButtonCount = 0;
}
}
}
LastButtonValue = ButtonValue;
//2nd Button

ButtonValue2 = digitalRead(PushButton2);
if(ButtonValue2 != LastButtonValue2){
delay(debounce); //DOuble check the press – is it real?
ButtonValue2 = digitalRead(PushButton2);
if(ButtonValue2 == HIGH && LastButtonValue2 == LOW){

ButtonCount2++; //add 1 to the Buttoncounter variable
Serial.println(ButtonCount2);
if (ButtonCount2>=4){ //if we count to four flash led twice
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
delay (200);
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
delay (200);
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
delay (200);
digitalWrite (led,HIGH);
delay (500);
digitalWrite (led,LOW);
ButtonCount2 = 0;
}
}
}
LastButtonValue2 = ButtonValue2;

//3rd Button

ButtonValue3 = digitalRead(PushButton3);
if(ButtonValue3 != LastButtonValue3){
delay(debounce); //DOuble check the press – is it real?
ButtonValue3 = digitalRead(PushButton3);
if(ButtonValue3 == HIGH && LastButtonValue3 == LOW){

ButtonCount3++; //add 1 to the Buttoncounter variable
Serial.println(ButtonCount3);
if (ButtonCount3>=3){ //if we count to five flash led twice
digitalWrite (red,HIGH);
delay (500);
digitalWrite (red,LOW);
delay (200);
digitalWrite (red,HIGH);
delay (500);
digitalWrite (red,LOW);
delay (200);
digitalWrite (red,HIGH);
delay (500);
digitalWrite (red,LOW);
ButtonCount3 = 0;
}
}
}

LastButtonValue3 = ButtonValue3; ///mnake a note of a state we’re in for the next loop.

//4th Button

ButtonValue4 = digitalRead(PushButton4);
if(ButtonValue4 != LastButtonValue4){
delay(debounce); //DOuble check the press – is it real?
ButtonValue4 = digitalRead(PushButton4);
if(ButtonValue4 == HIGH && LastButtonValue4 == LOW){

ButtonCount4++; //add 1 to the Buttoncounter variable
Serial.println(ButtonCount4);
if (ButtonCount4>=2){ //if we count to five flash led twice
digitalWrite (red,HIGH);
delay (500);
digitalWrite (red,LOW);
delay (200);
digitalWrite (red,HIGH);
delay (500);
digitalWrite (red,LOW);
ButtonCount4 = 0;
}
}
}

LastButtonValue4 = ButtonValue4; ///mnake a note of a state we’re in for the next loop.

 
} //closing void loop

Advertisements

One thought on “Its a combination lock and then some- Niki Selken

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s