2 button password modification

Pretty new to this...so please bear with me. I currently have a two push-button password circuit working... Press the correct button sequence (0, 1, 1, 1, 0), LEDs light up, etc... (I found a 4-button code, but modified it for 2 buttons).

what I'd like to do is modify my code to have 2 sequences to do something... for example:

type in first PIN code...light up LED and within 15 seconds, type in the 2nd PIN code and do something.

below is my code...Any help is appreciated!

#define RED 13 //red led
#define GREEN 12 //green led
#define BLUE 11 //blue led
#define VIBE 10 //vibe motor

const int pin[] = {0, 1, 1, 1, 0}; // The code to unlock
const int pinLength = sizeof(pin) / sizeof(int); // Length of the code

const int buttons[] = {3, 2}; // Arduino pins the buttons are connected to
const int buttonsLength = sizeof(buttons) / sizeof(int); // Number of buttons connected
bool pressed[buttonsLength]; // Which buttons were pressed pressed when last checked

int index = 0; // Index of current pin digit
bool correct = true; // If input matches pin
int attempt = 0;

//these will be used for button 1 prior to entering unlock PIN
int buttonState = 0;
int buttonPushCounter = 0;
int lastbuttonState = 0;

int randnum;

void setup() {
// Set LED and unlock pins to output

Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(VIBE, OUTPUT);
// Set buttons to inputs
for (int i = 0; i < buttonsLength; ++i) {
pinMode(buttons*, INPUT);*

  • }*
    }
    void loop() {
  • // digitalWrite(VIBE, !index); // Show blue LED if index is 0*
  • // Loop buttons*
  • for (int i = 0; i < buttonsLength; ++i) {*
  • //If the button is pressed*
    _ if (digitalRead(buttons*)) {_
    _ if (pressed) return; // Ignore if already pressed*
    pressed = true; // Set current button as pressed
    * correct = correct && i == pin[index]; // If the pin doesn't match set correct to false*
    * if (++index == pinLength) { // Increment digit index and check if last digit*
    * if (correct) { // Unlock and show green LED if code is correct*
    * digitalWrite(GREEN, HIGH);
    delay(3000);
    digitalWrite(GREEN, LOW);
    digitalWrite(BLUE, HIGH);
    delay(3000);
    digitalWrite(BLUE, LOW);
    attempt = 0; // Reset timer*

    * //vibe motor setup:: if 3, vibe for 3x, other wise,vibrate for 3 sec.
    randnum = random(1, 4);
    Serial.println(randnum);
    if ((randnum != 3))
    {
    Serial.println("SUCCESS");
    for (int x = 0; x < 3; ++x)
    {
    digitalWrite(VIBE, HIGH);
    delay(1000);
    digitalWrite(VIBE, LOW);
    delay(1000);
    }//end blink 3 times after success*

    * }//end of rand gen for vib motor*
    * else*
    * {
    Serial.println("FAILURE");
    digitalWrite(VIBE, HIGH);
    delay(3000);
    digitalWrite(VIBE, LOW);
    }//end if not 3, then fail*

    * } else { // The code is incorrect*
    * attempt++; // Increase a timer*
    * for (int j = 0; j < attempt; j++) { // Take longer if is not first attempt*
    * for (int k = 0; k < 5; k++) { // Flash red LED*
    * digitalWrite(RED, HIGH);
    delay(100);
    digitalWrite(RED, LOW);
    delay(100);
    }
    }
    }
    // Reset for next attempt*

    * index = 0;
    correct = true;
    }
    } else { // Button is not pressed*

    pressed = false; // Set current button as not pressed
    * }
    }
    delay(10); // Run every 10ms*

    }//end main loop_

Use CTRL T to format your code.
Attach your sketch between code tags
[code]Paste your sketch here[/code]

Show us a good schematic & image of your circuit wiring.
Posting images:
http://forum.arduino.cc/index.php?topic=519037.0

I just edited the post and had it formatted...... Also, attached is a circuit diagram

so basically, I want to type in once sequence.... and then give a 15 second period to then enter a 2nd sequence and then run the vibe motor upon successful 2nd sequence....

Currently the code will take one correct sequence, blink some LEDs if it's correct and then vibrate....otherwise, it just blinks red if the sequence is incorrect.

LEDs are drawn backwards.
Do not connect a motor directly to an Arduino o/p.
Suggest you use one resistor for each LED.

if (digitalRead(buttons)) this is not the way to read your two switches.

if (pressed) return; do you know where you will return to?

correct = correct && i == pin[index]; tell us what you think is happening here.

Use CTRL T to format your code.
Attach your sketch between code tags
[code]Paste your sketch here[/code]

Ok... yep, I realized that I have the LEDs backwards in the schematic...but on my breadadboard, are wired correctly...somewhere on the forum, I read that it wasn't necessary for the motor to have a resistor... hasn't failed yet, but I guess I can put on there... Lastly, like I said, the code was from a 4-button password sketch... I modified it for two buttons and changed up some of the LED blinking schemes...Other than that, the code actually works for 1 password. Where I'm stuck is not knowing how to implement a 2nd follow-on button sequence. Like I said, I want to enter the first sequence...flash an led, enter 2nd sequence, run the vibe motor (sequentially) not mutually exclusive... I assume it's somewhere inside of the "if (correct)" statement...as that kind of makes sense to me, that if the first sequence is correct, gather the 2nd sequence...and if that's correct, THEN run the vibe motor, otherwise, blink red 3 times to let the user know it's incorrect and start over by gathering 1st sequence... Hope that helps.

#define RED 13
#define GREEN 12
#define BLUE 11
#define VIBE 10
//#define LOCK 6
const int pin2[] = {1, 1, 1}; // Enter this pin second
const int pin[] = {0, 1, 1, 1, 0}; // Enter this pin first
const int pinLength2 = sizeof(pin2) / sizeof(int); //length of covert pin
const int pinLength = sizeof(pin) / sizeof(int); // Length of the code
const int buttons[] = {3, 2}; // Arduino pins the buttons are connected to
const int buttonsLength = sizeof(buttons) / sizeof(int); // Number of buttons connected
bool pressed[buttonsLength]; // Which buttons were pressed pressed when last checked
int index = 0; // Index of current pin digit
int index2 = 0; //same as above but for 2nd sequence
bool correct = true; // If input matches pin
bool correct2 = true; //if input matches covert pin
int attempt = 0;
int randnum;

void setup() {
// Set LED and unlock pins to output
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(VIBE, OUTPUT);
// Set buttons to inputs
for (int i = 0; i < buttonsLength; ++i) {
pinMode(buttons*, INPUT);*

  • }*
    }
    void loop() {
  • // digitalWrite(VIBE, !index); // Show blue LED if index is 0*
  • // Loop for buttons*
  • for (int i = 0; i < buttonsLength; ++i) {*
  • //If the button is pressed*
  • if (digitalRead(buttons[ i ] )) {*
    _ if (pressed*) return; // Ignore if already pressed*_
    _ pressed = true; // Set current button as pressed
    * correct = correct && i == pin[index]; // If the pin doesn't match set correct to false*
    * if (++index == pinLength) { // Increment digit index and check if last digit*
    * if (correct)
    { // Unlock and show green LED if code is correct*_

* digitalWrite(GREEN, HIGH);*
* delay(3000);*
* digitalWrite(GREEN, LOW);*
* delay(1000);*
* digitalWrite(BLUE, HIGH);*
* delay(3000);*
* digitalWrite(BLUE, LOW);*
* delay(5000);*
* attempt = 0; // Reset timer*
* } else { // The PIN code is incorrect*
* attempt++; // Increase a timer*
* for (int j = 0; j < attempt; j++) { // Take longer if is not first attempt*
* for (int k = 0; k < 5; k++) { // Flash red LED*
* digitalWrite(RED, HIGH);*
* delay(100);*
* digitalWrite(RED, LOW);*
* delay(100);*
* }*
* }*
* }*
* // Reset for next attempt*
* index = 0;*
* correct = true;*
* }*
* } else { // Button is not pressed*
_ pressed = false; // Set current button as not pressed
* }
}
delay(10); // Run every 10ms*

}//end main loop_

It appears you only want someone to correct your code.

You ignore posts that are trying to help, post #4 and #5 #3.

Good luck.

False. I'd like someone to point me in the right direction. Not correct my code. Why'd you ask to see it, if you're going to be condescending? The code works for one password already. I just wanted pointers on how to implement a sequential password. Thanks anyway.

const int pin2[] = {1, 1, 1}; // Enter this pin second
const int pin[] = {0, 1, 1, 1, 0}; // Enter this pin first
const int pinLength2 = sizeof(pin2) / sizeof(int); //length of covert pin
const int pinLength = sizeof(pin) / sizeof(int); // Length of the code

Why do you need ints to hold values in the range 0 to 1?

Numbering one of a pair of seemingly related variables makes it look like the second set was an afterthought. Probably not the impression you want to give.

When, EXACTLY, do you want to use one set? The other set?