setting an output

here is my sketch i want to set ledpin1 and ledpin2 as outputs but everytime i try i get error message

#include <Password.h> //
#include <Keypad.h> //

Password password = Password( "001" );
Password password2 = Password( "002" );
int ledPin1 = 13;
int ledPin2 = 12;
const byte ROWS = 4; // 4 rows
const byte COLS = 3; // 3 columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = { 5,4,3,2};
byte colPins[COLS] = { 8,7,6, };

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '#':
checkPassword();
checkPassword2();
break;
case '*':
password.reset();
password2.reset();
break;
default:
password.append(eKey);
password2.append(eKey);
}
}
}

void checkPassword(){
if (password.evaluate()){
digitalWrite(ledPin1, HIGH);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(2000);
digitalWrite(ledPin2, LOW);
password.reset();
password2.reset();
}
}
void checkPassword2(){
if (password2.evaluate()){
digitalWrite(ledPin2, HIGH);
delay(1000);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin1, HIGH);
delay(2000);
digitalWrite(ledPin1, LOW);
password.reset();
password2.reset();
}
}

collyd21:
i try i get error message

Yet you're not going to share that error message with us?

At the very least you haven't set up the LED pins with a pinMode() call.

pinMode(ledpin1, OUTPUT);

Should be in setup.

No idea if this is causing your error. I think probably not. Like Paul says seeing the actual error would help.

My money is betting on the error being it can't locate the password library. but just a guess based on my post count. :smiley:

Lefty

when i try

pinMode(ledpin1, OUTPUT);

this is the error i get

_2pass:16: error: expected constructor, destructor, or type conversion before '(' token

Whats on the line above that one?

better yet, what's the whole sketch look like now? Did you setup both pins as outputs?

Post the code again, but in a Code block. Select code and press the # button above.

#include <Password.h> //
#include <Keypad.h> //

Password password = Password( "001" );
Password password2 = Password( "002" );
int ledPin1 = 13; 
int ledPin2 = 12;
const byte ROWS = 4; // 4 rows
const byte COLS = 3; // 3 columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = { 5,4,3,2};
byte colPins[COLS] = { 8,7,6, };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  pinMode(ledPin1, OUTPUT);     
}

Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
  case PRESSED:
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey){
     case '#':
        checkPassword(); 
        checkPassword2();
        break;
     case '*':
        password.reset();
        password2.reset();
        break;
     default:
        password.append(eKey);
        password2.append(eKey);
  }
}
}

void checkPassword(){
if (password.evaluate()){
    digitalWrite(ledPin1, HIGH);
    delay(1000);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
    delay(2000);
    digitalWrite(ledPin2, LOW);
    password.reset();
    password2.reset();
}
}
void checkPassword2(){
if (password2.evaluate()){
digitalWrite(ledPin2, HIGH);
    delay(1000);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin1, HIGH);
    delay(2000);
    digitalWrite(ledPin1, LOW);
    password.reset();
    password2.reset();
}
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

void setup(){
  pinMode(ledPin1, OUTPUT);     
}   <-------- stray brace - get rid of it.

Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

If you used the IDE's formatting feature it would have caught the stray brace.

thanks its sorted now, how do i use ide format feature?

ctrl-t

There's probably a menu option on the edit menu. But who uses those?

Other handy Arduino IDE keyboard shortcuts:

ctrl-s save
ctrl-r verify
ctrl-u upload

thanks jimmy60, any chance you know anything about running a 12v dc pump with the arduino, i tried using a tip102 transistor with an external 12v psu, but when i turn the psu on it runs staright away.

ideally what i want to do is have a passcode put into my keypad and it'll turn one pump on and a second password turn a 2nd pump one.

the passcode sketch i have uploaded works already fine but when i ry rig the pump up i'm getting nowhere

i have it rigged up like this

http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

i have a small bank of 4 relays if its possible to use these instead?

Sorry, electronics isn't my strong suit. I'd just use relays.

To find out if there is a better way post that question in General Electronics.

Try a simpler piece of code to show you whether you have control of the motors and whether your wiring is correct. The Blink example could easily be adapted to this purpose.