Pages: [1]   Go Down
Author Topic: Keypad.getState()  (Read 1814 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guys!
I wrote this piece of code but I'm not sure if it work fine. I cannot test it because I don't have the Arduino yet.

My doubt is about the while condition, if I hold on the button "*" the function getState() will be  "PRESSED" or after some time it will change in "HOLD" ?
Another question, if I push the button 1 and while I hold the button 1 I push the button 2, the getKey function will be 1 or 2 ?

Code:
void active(){
  Serial.print(" * has been pressed");
  flash(ledPin,100); //flash a led for 0.1 sec.
  unsigned long pressTime=millis();  
  while(keypad.getState()==PRESSED){
    if ((millis()-pressTime)>activationTime){
      Serial.println("The button * has been pressed for more than 2 sec");
      flash(ledPin,1000);
      allarmActive=true;
      pressTime=millis(); //so, out of the if condition
    }      
  }
}
« Last Edit: March 24, 2011, 12:53:58 pm by davidino81 » Logged

Pages: [1]   Go Up
Jump to: