Wie kann ich eine Tastatureingabe (Pc-Tastatur) als Zeichen auf einem LCD ausgeben?
Ich habe bis jetzt dies hier:
/*
PS/2 Keyboard Input
*/
#include <LiquidCrystal.h>
#define LED 13
#define CLK 7
#define DAT 6
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// if I put the keyboard map in here then keys[scan code] would return
// the ascii value of the scan code.
unsigned char keys[128] =
{
};
void setup()
{
pinMode(LED, OUTPUT);
pinMode(CLK, INPUT);
pinMode(DAT, INPUT);
digitalWrite(CLK, HIGH);
digitalWrite(DAT, HIGH);
delayMicroseconds(50);
Serial.begin(9600);
lcd.display();
lcd.begin(16, 2);
}
void loop()
{
byte b = readkey();
if (b == 0xF0)
{
// key released
b = readkey();
}
else
{
// Serial.print(b, HEX);
lcd.print(b,HEX);
Serial.print(" ");
}
}
byte readkey()
{
byte _start = 0;
byte buf = 0;
byte _parity = 0;
byte _stop = 0;
waitClockLow();
_start = digitalRead(DAT);
if (_start == 0)
{
waitClockLow();
for (byte c=0; c<8; c++)
{
buf = buf | (digitalRead(DAT) << c);
waitClockLow();
}
_parity = digitalRead(DAT);
waitClockLow();
_stop = digitalRead(DAT);
}
return buf;
}
void waitClockLow()
{
if (digitalRead(CLK) == LOW)
while (digitalRead(CLK) == LOW)
{
}
while (digitalRead(CLK) == HIGH)
{
}
}
Da wird mir der Tastendruck als HEX ausgegeben.
Versuche mit sprintf haben mich auch nicht weitergebracht