Hi, I'm new to Arduino and programming in general so sorry if this is a stupid question.
Using the Keypad library, I'm trying to compare a function that fetches the status of a key to one of the strings that the function returns, inside a while loop and it returns an error message. Being a new programmer, I'm not sure what I am doing wrong. Any insight is greatly appreciated. Thanks in advance.
Here is the line: while(KeyState getState()==PRESSED) {}
Here is the error message:
Arduino: 1.6.9 (Mac OS X), Board: "Arduino/Genuino Uno"
/Users/DMac/Documents/Arduino/Keypad/KeypadSketch/KeypadSketch.ino: In function 'void loop()':
KeypadSketch:30: error: expected primary-expression before 'getState'
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:30: error: expected ')' before 'getState'
KeypadSketch:30: error: 'getState' was not declared in this scope
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:30: error: expected ';' before ')' token
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:35: error: expected primary-expression before 'getState'
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:35: error: expected ')' before 'getState'
KeypadSketch:35: error: 'getState' was not declared in this scope
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:35: error: expected ';' before ')' token
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:40: error: expected primary-expression before 'getState'
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:40: error: expected ')' before 'getState'
KeypadSketch:40: error: 'getState' was not declared in this scope
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:40: error: expected ';' before ')' token
while(KeyState getState()==PRESSED) {}
^
KeypadSketch:45: error: expected primary-expression before '{' token
if(myPassword=={5,2,5,3})
^
KeypadSketch:45: error: expected ')' before '{' token
exit status 1
expected primary-expression before 'getState'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
If you need it, here is the whole program:
//http://playground.arduino.cc/Code/Keypad
#include <Keypad.h>
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'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6, 9}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
int myPassword[4];
char waitForKey();
myPassword[0] = customKeypad.getKey();
tone(10,941,250);
Serial.println(myPassword[0]);
while(KeyState getState()==PRESSED) {}
char waitForKey();
myPassword[1] = customKeypad.getKey();
tone(10,941,250);
Serial.println(myPassword[1]);
while(KeyState getState()==PRESSED) {}
char waitForKey();
myPassword[2] = customKeypad.getKey();
tone(10,941,250);
Serial.println(myPassword[2]);
while(KeyState getState()==PRESSED) {}
char waitForKey();
myPassword[3] = customKeypad.getKey();
tone(10,941,250);
Serial.println(myPassword[3]);
if(myPassword=={5,2,5,3})
{ tone(10,1500,250);
delay(25);
tone(10,1750,250);
delay(25);
tone(10,2000,250);
delay(25);
/*relay*/ }
else {
tone(10,300,250);
delay(25);
tone(10,300,250);
delay(25);
tone(10,300,250);
delay(25);
}}