-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESP32-USB-Keyboard.ino
41 lines (34 loc) · 1.15 KB
/
ESP32-USB-Keyboard.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//********************************************************************************
// USB keyboard ESP32 Test by Nathalis.
//********************************************************************************
#include <PS2KeyAdvanced.h>
/* Define pins used for data and clock from keyboard (check connection schematic) */
#define DATAPIN 19
#define IRQPIN 18
uint16_t c;
PS2KeyAdvanced keyboard;
void setup( )
{
Serial.begin( 9600 );
Serial.println( "USB Keyboard Test:" );
// Configure the keyboard library
keyboard.begin(DATAPIN,IRQPIN);
keyboard.echo(); // ping keyboard to see if there
delay(3);
c = keyboard.read();
if ((c & 0xFF)==PS2_KEY_ECHO || (c & 0xFF)==PS2_KEY_BAT) Serial.println("Keyboard OK.."); // Response was Echo or power up
else if ((c & 0xFF)==0) Serial.println("Keyboard Not Found");
else {
Serial.print( "Invalid Code received of " );
Serial.println( c, HEX );
}
}
void loop( )
{
if ( keyboard.available()) {
// read the next key
c = keyboard.read( );
if ( ( c & 0xFF ) > 0 ) Serial.println( c , HEX );
delay(3);
}
}