33 Records 8 bits at 110 baud.
44*/
55
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)
88
99void setup () {
10- pinMode (LED_BUILTIN, OUTPUT);
1110 pinMode (resetPin, OUTPUT);
1211 pinMode (dataPin, INPUT);
1312
@@ -20,37 +19,38 @@ void setup() {
2019 Serial.println (" Hello logic_analyzer" );
2120}
2221
23- // Microseconds to wait between bits
22+ // Microseconds to wait between bits. Corresponds to 110 baud.
2423const int baudDelay = 3333 ;
24+ int allData[9 ];
2525
2626void loop () {
2727 int data = digitalRead (dataPin);
2828 if (data == LOW) {
29- digitalWrite (LED_BUILTIN, HIGH);
30- // Serial.print("START: ");
3129 int index = 0 ;
32- int allData[9 ];
3330 int theKey = 0 ;
31+
3432 // Wait half a cycle so that we're sampling in the middle of the bit.
3533 delayMicroseconds (baudDelay / 2 );
3634 while (index <= 8 ) {
3735 data = digitalRead (dataPin);
36+
3837 allData[index++] = data;
38+ // Shift right and possibly shift in a 1.
39+ theKey >>= 1 ;
3940 if (data == HIGH) {
40- theKey = (theKey >> 1 ) | 0x80 ;
41- } else {
42- theKey = (theKey >> 1 );
41+ theKey = theKey | 0x80 ;
4342 }
43+
4444 // Wait for the next bit
4545 delayMicroseconds (baudDelay);
4646 }
47+
4748 Serial.print (" YOU TYPED: " );
4849 Serial.print ((char )theKey);
4950 Serial.print (" (" ); Serial.print (theKey); Serial.print (" =0b" );
5051 for (int i = index - 1 ; i >= 0 ; i--) {
5152 Serial.print (allData[i]);
5253 }
5354 Serial.println (" )" );
54- digitalWrite (LED_BUILTIN, LOW);
5555 }
5656}
0 commit comments