Hello everyone,
I have a gear head keypad Robot or human? and I can't figure out how to get it to register on my arduino.
I'm trying to follow this http://www.libelium.com/tienda/catalog/includes/languages/english/pdf/LIFE_HACKS-WINNER-ARDUINO_SECURITY.pdf project. The code is copied except I added in a relay.
When I plug the keypad into the ps/2 adapter, connected to my arduino, the numlock LED lights up for a short second, then it shuts off.
When I plug the keypad into a computer, nothing happens for about 5 seconds, then you get messages on your monitor saying the computer is looking for new hardware. Then it found new hardware. Lastly, you can use your new hardware.
I don't of course get any of this on my arduino.
Does anyone know how to register such a keypad?
#define DEBUG 0
#define VERSION "v0.7 17Apr2008"
//SCANCODES PS/2 KEYBOARDS
#define SCAN_ENTER 0xE0
#define SCAN_BREAK 0xf0
byte scanCodes[10] = {0x70,0x69,0x72,0x7A,0x6B,0x73,0x74,0x6C,
0x75,0x7D};
char characters[10] = {'0','1','2','3','4','5','6','7','8','9'};
int quantityCodes = 10;
//KEYBOARD HANDLING VARS
byte dataValue;
// PINS
int clockPin = 3; //KEYBOARD CLK
int dataPin = 2; //KEYBOARD DAT
int soundPin = 9; // TEST
int servoPin = 10;
int closePin = 7;// DOOR "Switch"
int speakerPin = 12; //Optional Speaker VCC
int relay = 1; //What I added
// PASSWORD
char mypass[11]="12345\0";
char pass[11];
int passlen=0;
char letra;
void setup()
{
pinMode(dataPin, INPUT);
pinMode(clockPin, INPUT);
pinMode(closePin, INPUT);
pinMode(speakerPin, OUTPUT);
pinMode(relay, OUTPUT); //What I added
if (DEBUG)
{
Serial.begin(9600);
analogWrite(soundPin,100);
Serial.println("ARDUINO DOOR OPENER ONLINE");
Serial.println(VERSION);
}
startupSound();
}
void loop()
{
dataValue = dataRead();
if (dataValue == SCAN_BREAK)
{
dataValue = dataRead(); // Reading the key that wasepressed
dataValue = dataRead(); // Wait for and read a new key
}
pinMode(clockPin,OUTPUT);
digitalWrite(clockPin,LOW);
for (int i = 0; i < quantityCodes; i++)
{
byte temp = scanCodes[i];
if (temp == dataValue || dataValue == SCAN_ENTER)
{
letra=characters[i];
if (DEBUG) Serial.println(letra);
// If enter read
if(dataValue == SCAN_ENTER)
{
digitalWrite(clockPin,HIGH);
pinMode(clockPin,INPUT);
dataValue = dataRead();
pinMode(clockPin,OUTPUT);
digitalWrite(clockPin,LOW);
if(dataValue == 0x5A)
{pass[passlen+1]='\0';
if (strcmp(pass,mypass)==0)
{Serial.println("Abriendo");OpenDoo();
}
else {errorSound(); for (int i=0;i<=passlen; i++)
{Serial.print(pass[i]);}
}
Serial.println();
for (int i=0; i<=10; i++) pass[i]='\0';
passlen=0;
}
}
//if not enter read
else
{pass[passlen]=letra;
if (DEBUG)
{
Serial.print(letra); Serial.print(" ");
Serial.print(pass[passlen]);Serial.print(" ");
Serial.print(passlen);
Serial.print(" PASS="); for (int i=0; i<=passlen; i++)
Serial.print(pass[i]); Serial.println();
}
passlen++;
if (passlen==10) passlen=0;
}
dataValue = 0;
letra=0;
//delay(200);
}
}
digitalWrite(clockPin,HIGH);
pinMode(clockPin,INPUT);
}
void OpenDoor()
{
// OPEN
digitalWrite(relay, HIGH); //What I added
delay(3000);
analogWrite(servoPin,40);
openSound();
delay(3000);
analogWrite(servoPin,0);
while (!digitalRead(closePin)) delay(250);
//CLOSE
digitalWrite(relay, LOW); //What I added
analogWrite(servoPin,220);
closeSound();
delay(2000);
analogWrite(servoPin,0);
}
int dataRead() {
byte val = 0;
int v = 0;
while (digitalRead(clockPin)); // Waiting for LOW
while (!digitalRead(clockPin));// Waiting for HIGH
while (digitalRead(clockPin)); // Waiting for LOW
for (int offset = 0; offset < 8; offset++)
{
while (digitalRead(clockPin)); // Waiting for LOW
val |= digitalRead(dataPin) << offset; // Adding to byte
while (!digitalRead(clockPin)); // Waiting for HIGH
}
while (digitalRead(clockPin)); // Waiting for LOW
while (!digitalRead(clockPin)); // Waiting for HIGH
while (digitalRead(clockPin)); // Waiting for LOW
while (!digitalRead(clockPin)); // Waiting for HIGH
return val;
}
void errorSound()
{
int n = 2000;
for (int vez=0;vez<2;vez++){
for (int _=0;_<30;_++){
delayMicroseconds(n);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(n);
digitalWrite(speakerPin, LOW);
}
delay(50);
}
}
void openSound()
{
int n = 300;
for (int vez=0;vez<3;vez++){
for (int _=0;_<100;_++){
delayMicroseconds(n);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(n);
digitalWrite(speakerPin, LOW);
}
delay(100);
}
}
void closeSound()
{
int n = 300;
for (int vez=0;vez<2;vez++){
for (int _=0;_<100;_++){
delayMicroseconds(n);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(n);
digitalWrite(speakerPin, LOW);
}
delay(100);
}
n = 450;
for (int _=0;_<110;_++){
delayMicroseconds(n);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(n);
digitalWrite(speakerPin, LOW);
}
}
void startupSound()
{//RE MI DO DO. SOL
int note = (1/587.33)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/659.26)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/523.25)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/261.63)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/392.00)*500000;
for (int _=0;_<200000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
}