Program for keypads - SOLVED!

Hello everyone,

Today I received a keypad. I installed the library and wrote the following program for it:

#include <keypad.h>

char* secretCode = "1234";
int position = 0;

const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[rows] = {2, 7, 6, 4};
byte colPins[cols] = {3, 1, 5};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

int redPin = 9;
int greenPin = 8;

void setup (){
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
setLocked(true);
}
void loop (){
char key = keypad.getKey();
if (key == '*' || key == '#')
{
position = 0;
setLocked(true);
}
if (key == secretCode[position])
{
position ++;
}
if (position == 4)
{
setLocked(false);
}
delay(100);
}

void setLocked(int Locked){
if (locked)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
}
else
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
}
}

When it is verified, a warning comes up, saying that " 'keypad' does not name a type". I'm just wondering what this means, and how to solve it really. Please help.

Should be capital
#include <keypad.h>

These don't match.
void setLocked(int Locked){
if (locked)

The error is still coming up when the program is verified.

Where did you put the library? It should be in a "libraries" folder in the Arduino sketch folder, which should be located in your Mydocuments.

The keypad library is in the correct folder, and it's still saying the error. :frowning:

That same error or a different one? I tried your code and those were the only two mistakes that gave errors. The mistakes were fixed and now it compiles.

The keypad library is in the correct folder, and it's still saying the error.

Then, no it isn't. Instead of telling us that you think you installed the library in the right place, tell us WHERE you installed it, and we can confirm that that is indeed the correct place, or explain why it isn't.

You did restart the IDE after installing the library, right?

The path that I took for placing the library folder was the following:

My Documents/arduino/libraries

The arduino folder is the one that creates itself when you install the software.

The arduino software is saying that the error is in this part of the code:

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

Solved the problem. I had to re-install the library for some reason. Thanks for the help!

Thanks for the help!

Thank you for letting us know what the problem was.