Skip to content

Commit fa748e0

Browse files
committed
Simple keyboard interface. It really works.
Not done: shift, control
1 parent 0b93ee3 commit fa748e0

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Simple keyboard interface. Triggers when the data pin goes low.
3+
Records 8 bits at 110 baud.
4+
*/
5+
6+
const int dataPin = 2; // corresponds to pin 6 on the KB connector (and pin 6 of the RJ12)
7+
const int resetPin = 5; // corresponds to pin 2 on the KB connector (and pin 4 on the RJ12)
8+
9+
void setup() {
10+
pinMode(LED_BUILTIN, OUTPUT);
11+
pinMode(resetPin, OUTPUT);
12+
pinMode(dataPin, INPUT);
13+
14+
// Set the reset pin low for 10 ms.
15+
digitalWrite(resetPin , LOW);
16+
delay(10);
17+
digitalWrite(resetPin , HIGH);
18+
19+
Serial.begin(9600);
20+
Serial.println("Hello logic_analyzer");
21+
}
22+
23+
// Microseconds to wait between bits
24+
const int baudDelay = 3333;
25+
26+
void loop() {
27+
int data = digitalRead(dataPin);
28+
if (data == LOW) {
29+
digitalWrite(LED_BUILTIN, HIGH);
30+
// Serial.print("START: ");
31+
int index = 0;
32+
int allData[9];
33+
int theKey = 0;
34+
// Wait half a cycle so that we're sampling in the middle of the bit.
35+
delayMicroseconds(baudDelay / 2);
36+
while (index <= 8) {
37+
data = digitalRead(dataPin);
38+
allData[index++] = data;
39+
if (data == HIGH) {
40+
theKey = (theKey >> 1) | 0x80;
41+
} else {
42+
theKey = (theKey >> 1);
43+
}
44+
// Wait for the next bit
45+
delayMicroseconds(baudDelay);
46+
}
47+
Serial.print("YOU TYPED: ");
48+
Serial.print((char)theKey);
49+
Serial.print(" ("); Serial.print(theKey); Serial.print("=0b");
50+
for (int i = index - 1; i >= 0; i--) {
51+
Serial.print(allData[i]);
52+
}
53+
Serial.println(")");
54+
digitalWrite(LED_BUILTIN, LOW);
55+
}
56+
}

0 commit comments

Comments
 (0)