6
6
const int dataPin = 2 ; // corresponds to pin 6 on the KB connector (and pin 6 of the RJ12)
7
7
const int resetPin = 5 ; // corresponds to pin 2 on the KB connector (and pin 4 on the RJ12)
8
8
9
- int changed = 0 ;
10
-
11
9
void setup () {
12
10
pinMode (LED_BUILTIN, OUTPUT);
13
11
pinMode (resetPin, OUTPUT);
@@ -22,32 +20,47 @@ void setup() {
22
20
Serial.println (" Hello logic_analyzer" );
23
21
}
24
22
23
+ const int baudDelay=3333 ;
25
24
int data = 0 ;
26
- int inKey = 0 ; // are we reading a key?
27
- int numOnes = 0 ; // the # of 1s in a row
28
25
29
26
void loop () {
30
27
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 ;
36
30
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 );
43
50
numOnes = 0 ;
44
- digitalWrite (LED_BUILTIN, LOW);
45
- Serial.println (" END" );
46
- delay (500 );
51
+ // Serial.print(", 0, ");
52
+ // Serial.print(0);
47
53
}
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]);
51
61
}
62
+ Serial.println (" )" );
63
+ digitalWrite (LED_BUILTIN, LOW);
64
+ // Serial.println("END");
52
65
}
53
66
}
0 commit comments