# URGENT: help needed for school project!!!

In my Engineering class at school, we have a project where we build a new invention and it has to include some type of coding. My project is a knife block that locks the knives in place and unlocks when the correct passcode in put into a 4 x 4 keypad. What happens is an electromagnetic pull solenoid is in a notch in the knife and it is pulled in when the correct code is put in, then goes back out after a few seconds.

Right now with the code we have, the arduino recognizes the passcode and pulls in the solenoid when “1234” is entered into the keypad. However, it won’t reset, as a loop should, to allow the passcode to be put in again to unlock the knives again. I have tried putting in different things, but what I have currently just makes the solenoid go in again after I press “#”, “1”, “2”, “3”, or “4” and then stops.
Does anyone know of any way I can make the code reset and go back to the top of the code after each time the correct passcode has been entered and the solenoids have been pulled, or makes it so that every 4 digits entered is read as a different try?

int myPins[] = {'1', '2', '3', '4', '\0'};
int myPins2[] = {'5', '6', '7', '8', '\0'};

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'}, //digits in row 1
{'4','5','6','B'}, //digits in row 2
{'7','8','9','C'}, //digits in row 3
{'*','0','#','D'} //digits in row 4
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad

void setup(){
Serial.begin(9600);
pinMode(13, OUTPUT);
}

void loop() {
for (int increment=0; increment<5; increment++) {
keypressed=0;
while(keypressed==0) {
}
Serial.println(keypressed);

{
digitalWrite(13, HIGH);
delay(4000);
digitalWrite(13, LOW);
}
else
{
}
}
}

KnifeBeLocked-code.ino (1.28 KB)

Try to set answer to null after you write low to pin 13

swoy:
Try to set answer to null after you write low to pin 13

Dangerous; the next time a key is pressed one probably will get unexpected behaviour Clearing is probably better

``````memset(answer, 0, sizeof(answer));
``````

OP, next time please use code tags for posting code or error messages.

`** **[code]** **`
`** **[/code]** **`
will result in

``````your code here
``````