Skip to content

Commit 78bcd51

Browse files
committed
Hacking around. Mostly works.
1 parent fa748e0 commit 78bcd51

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

vg4_keyboard/logic_analyzer/logic_analyzer.ino

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
const int dataPin = 2; // corresponds to pin 6 on the KB connector (and pin 6 of the RJ12)
77
const int resetPin = 5; // corresponds to pin 2 on the KB connector (and pin 4 on the RJ12)
88

9-
int changed = 0;
10-
119
void setup() {
1210
pinMode(LED_BUILTIN, OUTPUT);
1311
pinMode(resetPin, OUTPUT);
@@ -22,32 +20,47 @@ void setup() {
2220
Serial.println("Hello logic_analyzer");
2321
}
2422

23+
const int baudDelay=3333;
2524
int data = 0;
26-
int inKey = 0; // are we reading a key?
27-
int numOnes = 0; // the # of 1s in a row
2825

2926
void loop() {
3027
data = digitalRead(dataPin);
31-
if (data == LOW && !inKey) {
32-
inKey = 1; // we're recording until numones==30
33-
numOnes = 0;
34-
Serial.println("START");
35-
Serial.print(micros()); Serial.print(", 0, ");
28+
if (data == LOW) {
29+
int numOnes = 0;
3630
digitalWrite(LED_BUILTIN, HIGH);
37-
} else if (inKey) {
38-
if (data == HIGH) {
39-
Serial.print(micros()); Serial.print(", 1, ");
40-
numOnes++;
41-
if (numOnes == 30) {
42-
inKey = 0;
31+
// Serial.print("START: ");
32+
// unsigned long started = micros();
33+
// Serial.print(0); Serial.print(", 0, ");
34+
int index = 0;
35+
int allData[9];
36+
int theKey=0;
37+
delayMicroseconds(baudDelay/2);
38+
while (index <= 8) {
39+
// unsigned long now = micros();
40+
data = digitalRead(dataPin);
41+
// Serial.print(now - started);
42+
allData[index++] = data;
43+
if (data == HIGH) {
44+
theKey = (theKey>>1)|0x80;
45+
//Serial.print(", 1, ");
46+
//Serial.print(1);
47+
numOnes++;
48+
} else {
49+
theKey = (theKey>>1);
4350
numOnes = 0;
44-
digitalWrite(LED_BUILTIN, LOW);
45-
Serial.println("END");
46-
delay(500);
51+
// Serial.print(", 0, ");
52+
//Serial.print(0);
4753
}
48-
} else {
49-
numOnes = 0;
50-
Serial.print(micros()); Serial.print(", 0, ");
54+
delayMicroseconds(baudDelay);
55+
}
56+
Serial.print("TYPED: ");
57+
Serial.print((char)theKey);
58+
Serial.print(" (");
59+
for (int i = 0; i < index; ++i) {
60+
Serial.print(allData[i]);
5161
}
62+
Serial.println(")");
63+
digitalWrite(LED_BUILTIN, LOW);
64+
// Serial.println("END");
5265
}
5366
}

0 commit comments

Comments
 (0)