PS/2KEYBOARD Password check

Hello!

I want to light the led when the password entered from the keyboard is the same as programm for leds ON and other password for led OFF. I use only the numpad.. so there is only numbers ... and I would like to make a delay after 3 incorect passwords entered...

something like :
passON=12345+; ( the + is the button '+' 0x79)
passOFF=12345enter ( the enter is the button 'Enter' 0xE0 0x5A ) if am right
if (passON== inpass)
digitalWrite(ledPin, HIGH);
if (passOFF== inpass)
digitalWrite(ledPin, LOW);

I'll use thes code ... I'm new in arduino, so i'll be happy if someone will help me...

#include <ps2.h>

PS2 kbd(3, 4);

void kbd_init()
{
  char ack;
  
  kbd.write(0xff);  // send reset code
  ack = kbd.read();  // byte, kbd does self test
  ack = kbd.read();  // another ack when self test is done
}

void setup()
{
  Serial.begin(9600);
  kbd_init();
  }
void loop()
{int m;
  unsigned char code; 
  
  for (;;) { /* ever */  
    /* read a keycode */
    code = kbd.read(); 
    
    
     }
}

untested: :slight_smile:

void resetMC(int8_t *m, const uint8_t sc) {
  for (int8_t s=sc-1; s>=0; s--)
    m[s] = 0;
}
void loop() {
  const uint8_t seqENTER[] = {
    0xE0,0x5A,0    };
  const uint8_t seqON[] = {
    'A','B','C',0    };
  const uint8_t seqOFF[] = {
    'a','b','c',0    };
  const uint8_t sc = 3;
  const uint8_t *seqs[sc] = {
    seqENTER,seqON,seqOFF    };
  int8_t match[sc];
  resetMC(match,sc);
  uint8_t error = 0;
  for (;;) {
    const uint8_t code = kbd.read();
    Serial.println((int)code,HEX);
    for (int8_t s=sc-1; s>=0; s--)
      if (match[s] >= 0 && seqs[s][match[s]] != 0 && code == seqs[s][match[s]]) {
        match[s]++;
        if (s != 0)
          continue;
        if (seqs[s][match[s]] == 0) {
          int8_t t;
          if (!fail) {
            for (t=sc-1; t>0; t--)
              if (match[t] > 0 && seqs[t][match[t]] == 0) {
                digialWrite(ledPin,t==1?LOW:HIGH);
                break;
              } 
          }
          if (fail || t == 0) {
            error++;
            if (error >= 3)
              delay(3*1000);
          }
          resetMC(match,sc);
          fail = 0;
        }
        break;
      } else
        match[s] = s==0 ? 0 : -1;
  }
}

modified... [smiley=beer.gif] [smiley=beer.gif] [smiley=beer.gif] [smiley=beer.gif] [smiley=beer.gif]

-arne