Hello all,
I'm trying to use 2 keyboards with PS2keyboard library, but only one works. I tried swapping pins but didn't help, I also tried duplicating the library and renaming the second one(also all declarations inside the library) but that didn't work either. Forgive me if it's dead easy, but I have no idea how to solve it.
This is the code, only one keyboard works:
#include <PS2Keyboard.h>
const int DataPin = 4;
const int IRQpin = 7;
const int DataPin2 = 3;
const int IRQpin2 = 2;
PS2Keyboard keyboard1;
PS2Keyboard keyboard2;
void setup()
{
Serial.begin(9600);
keyboard1.begin(DataPin, IRQpin);
keyboard2.begin(DataPin2, IRQpin2);
}
void loop()
{
if (keyboard1.available()) {
// read the next key
char c = keyboard1.read();
// check for some of the special keys
if (c == PS2_ENTER) {
Serial.print("e");
} else if (c == PS2_DELETE) {
Serial.print("f");
} else if (c == PS2_NUM) {
Serial.print("g");
} else if (c == '0') {
Serial.print("h");
} else if (c == '1') {
Serial.print("i");
} else if (c == '2') {
Serial.print("j");
} else if (c == '3') {
Serial.print("k");
} else if (c == '4') {
Serial.print("l");
} else if (c == '5') {
Serial.print("m");
} else if (c == '6') {
Serial.print("n");
} else if (c == '7') {
Serial.print("o");
} else if (c == '8') {
Serial.print("p");
} else if (c == '9') {
Serial.print("u");
} else if (c == '*') {
Serial.print("v");
} else if (c == '-') {
Serial.print("w");
} else if (c == '/') {
Serial.print("x");
} else if (c == '.') {
Serial.print("y");
} else if (c == '+') {
Serial.print("z");
} else {
// otherwise, just print all normal characters
Serial.write(c);
}
}
if (keyboard2.available()) {
// read the next key
char c = keyboard2.read();
// check for some of the special keys
if (c == PS2_ENTER) {
Serial.print("e");
} else if (c == PS2_DELETE) {
Serial.print("f");
} else if (c == PS2_NUM) {
Serial.print("g");
} else if (c== '0') {
Serial.print("h");
} else if (c == '1') {
Serial.print("i");
} else if (c == '2') {
Serial.print("j");
} else if (c== '3') {
Serial.print("k");
} else if (c == '4') {
Serial.print("l");
} else if (c == '5') {
Serial.print("m");
} else if (c == '6') {
Serial.print("n");
} else if (c == '7') {
Serial.print("o");
} else if (c == '8') {
Serial.print("p");
} else if (c == '9') {
Serial.print("u");
} else if (c == '*') {
Serial.print("v");
} else if (c == '-') {
Serial.print("w");
} else if (c == '/') {
Serial.print("x");
} else if (c == '.') {
Serial.print("y");
} else if (c == '+') {
Serial.print("z");
} else {
// otherwise, just print all normal characters
Serial.write(c);
}
}
}