3
3
Records 8 bits at 110 baud.
4
4
*/
5
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)
6
+ const int dataPin = 2 ; // pin 6 on the KB connector (and pin 6 of the RJ12)
7
+ const int resetPin = 5 ; // pin 2 on the KB connector (and pin 4 on the RJ12)
8
8
9
9
void setup () {
10
- pinMode (LED_BUILTIN, OUTPUT);
11
10
pinMode (resetPin, OUTPUT);
12
11
pinMode (dataPin, INPUT);
13
12
@@ -20,37 +19,38 @@ void setup() {
20
19
Serial.println (" Hello logic_analyzer" );
21
20
}
22
21
23
- // Microseconds to wait between bits
22
+ // Microseconds to wait between bits. Corresponds to 110 baud.
24
23
const int baudDelay = 3333 ;
24
+ int allData[9 ];
25
25
26
26
void loop () {
27
27
int data = digitalRead (dataPin);
28
28
if (data == LOW) {
29
- digitalWrite (LED_BUILTIN, HIGH);
30
- // Serial.print("START: ");
31
29
int index = 0 ;
32
- int allData[9 ];
33
30
int theKey = 0 ;
31
+
34
32
// Wait half a cycle so that we're sampling in the middle of the bit.
35
33
delayMicroseconds (baudDelay / 2 );
36
34
while (index <= 8 ) {
37
35
data = digitalRead (dataPin);
36
+
38
37
allData[index++] = data;
38
+ // Shift right and possibly shift in a 1.
39
+ theKey >>= 1 ;
39
40
if (data == HIGH) {
40
- theKey = (theKey >> 1 ) | 0x80 ;
41
- } else {
42
- theKey = (theKey >> 1 );
41
+ theKey = theKey | 0x80 ;
43
42
}
43
+
44
44
// Wait for the next bit
45
45
delayMicroseconds (baudDelay);
46
46
}
47
+
47
48
Serial.print (" YOU TYPED: " );
48
49
Serial.print ((char )theKey);
49
50
Serial.print (" (" ); Serial.print (theKey); Serial.print (" =0b" );
50
51
for (int i = index - 1 ; i >= 0 ; i--) {
51
52
Serial.print (allData[i]);
52
53
}
53
54
Serial.println (" )" );
54
- digitalWrite (LED_BUILTIN, LOW);
55
55
}
56
56
}
0 commit comments