Stap 2: Worden draadloze...
Laat de pinnen 4 en 5 van de arduin gebruikt voor de seriële communicatie, dus er is voor het importeren van de bibliotheek SoftwareSerial:
[code]
#include < SoftwareSerial.h >
[/ code]
Maak van een object met de naam blauwe en stel de gegevenssnelheid in 9600.
[code]
SoftwareSerial blue(4,5); RX, Tx
Blue.begin(9600);
[/ code]
De volledige code is:
[code]
#include < PS2Keyboard.h >
#include < SoftwareSerial.h >
char rec;
SoftwareSerial blue(4,5); RX, Tx
Const int PinData = 3;
Const int PinClock = 2;
PS2Keyboard teclado;
VOID Setup
{
delay(1000);
teclado.begin (PinData, PinClock);
Blue.begin(9600);
}
void loop
{/ / Als het toetsenbord beschikbaar is
Als (teclado.available())
{/ / Leest de ingedrukte toets
char c = teclado.read(); Sommige speciale toetsen wordt gecontroleerd
Als (c == PS2_ENTER)
{
Blue.println("ent");
}
anders als (c == PS2_TAB)
{
Blue.println("tab");
}
anders als (c == PS2_ESC)
{
Blue.println("ESC");
}
anders als (c == PS2_BACKSPACE)
{
Blue.println("BSP");
}
anders als (c == PS2_PAGEDOWN)
{
Blue.println("PGD");
}
anders als (c == PS2_PAGEUP)
{
Blue.println("pgu");
}
anders als (c == PS2_LEFTARROW)
{
Blue.println("lft");
}
anders als (c == PS2_RIGHTARROW)
{
Blue.println("RGT");
}
anders als (c == PS2_UPARROW)
{
Blue.println("UPK]");
}
anders als (c == PS2_DOWNARROW)
{
Blue.println("DWN");
}
anders als (c == PS2_DELETE)
{
Blue.println("del");
}
anders
{/ / De normale tekens afdrukken
Blue.println(c);
}
}
}
[/ code]
Download hier de code voor de arduino.
Volgende stap krijg de toetsen verzenden...