combinationLock (somethings up with my arduino UNO)

int buttonPin= 2;

int buttonState;
int lastButtonState = 0;
int buttonPushCounter = 1;

int buzzPin = 11;

int ledPin_1 = 12; //red
int ledPin_2 = 13; //blue

void setup(){
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(buzzPin, OUTPUT);
pinMode(ledPin_1, OUTPUT);
pinMode(ledPin_2, OUTPUT);
}

void lastchance(){
buttonState = digitalRead(buttonPin);
if(buttonState != lastButtonState){
if(buttonState == HIGH){
buttonPushCounter++;

Serial.println(“on”);
Serial.println(“# of button pushes: “);
Serial.println(buttonPushCounter-1);

// delay(10);
}
else{
Serial.println(“off”);
}
}
lastButtonState = buttonState;
// delay(10);
}

void loop(){

lastchance();

if(buttonPushCounter % 5 == 0){
digitalWrite(ledPin_2, HIGH);
digitalWrite(ledPin_1, LOW);
noTone(8);

}else{
digitalWrite(ledPin_1, HIGH);
digitalWrite(ledPin_2, LOW);
tone(buzzPin, 500);

}
}

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s