Skip to content

Commit dae9275

Browse files
committed
Reverted logic analyzer to be a more generic logic analyzer.
1 parent d736e4b commit dae9275

File tree

1 file changed

+54
-38
lines changed

1 file changed

+54
-38
lines changed

logic_analyzer/logic_analyzer.ino

+54-38
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,82 @@
11
/*
2-
Simple logic analyzer. Triggers when the data pin goes low.
3-
Records bits until 30 1's in a row are received.
2+
* Simple logic analyzer. Triggers when the data pin goes low.
3+
* Records bits until 30 1's in a row are received.
4+
* Attemps to debounce the button (poorly). Resets the board
5+
* (reset pin low) when the button is pressed, and starts listening.
46
*/
57

8+
const int buttonPin = 7; // the number of the pushbutton pin
69
const int dataPin = 2; // corresponds to pin 6 on the KB connector (and pin 6 of the RJ12)
710
const int resetPin = 5; // corresponds to pin 2 on the KB connector (and pin 4 on the RJ12)
811

12+
int buttonState = 0; // variable for reading the pushbutton status
13+
914
void setup() {
1015
pinMode(LED_BUILTIN, OUTPUT);
16+
pinMode(buttonPin, INPUT);
1117
pinMode(resetPin, OUTPUT);
1218
pinMode(dataPin, INPUT);
1319

1420
// Set the reset pin low for 10 ms.
15-
digitalWrite(resetPin , LOW);
21+
digitalWrite(resetPin, LOW);
1622
delay(10);
17-
digitalWrite(resetPin , HIGH);
23+
digitalWrite(resetPin, HIGH);
1824

19-
Serial.begin(1000000);
25+
Serial.begin(9600);
2026
Serial.println("Hello logic_analyzer");
2127
}
2228

23-
const int baudDelay=3333;
29+
int changed = 0;
30+
int shouldRead = 0;
2431
int data = 0;
32+
int inKey = 0; // are we reading a key?
33+
int numOnes = 0; // the # of 1s in a row
2534

2635
void loop() {
27-
data = digitalRead(dataPin);
28-
if (data == LOW) {
29-
int numOnes = 0;
36+
// read the state of the pushbutton value:
37+
buttonState = digitalRead(buttonPin);
38+
39+
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
40+
if (buttonState == HIGH && !changed) {
41+
// turn LED on, and toggle recording.
3042
digitalWrite(LED_BUILTIN, HIGH);
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+
Serial.println("on");
44+
shouldRead = 1 - shouldRead;
45+
Serial.print("ShouldRead is "); Serial.println(shouldRead);
46+
changed = 1;
47+
} else if (buttonState == LOW && changed) {
48+
// turn LED off:
49+
digitalWrite(LED_BUILTIN, LOW);
50+
Serial.println("off");
51+
changed = 0;
52+
53+
// beep/reset, and keep reading.
54+
digitalWrite(resetPin , LOW);
55+
delay(10);
56+
digitalWrite(resetPin , HIGH);
57+
}
58+
59+
if (shouldRead == 1) {
60+
data = digitalRead(dataPin);
61+
if (data == LOW && !inKey) {
62+
inKey=1; // we're recording until numones==30
63+
numOnes=0;
64+
Serial.println("START");
65+
Serial.println("0");
66+
} else if (inKey) {
4367
if (data == HIGH) {
44-
theKey = (theKey>>1)|0x80;
45-
//Serial.print(", 1, ");
46-
//Serial.print(1);
68+
Serial.println("1");
4769
numOnes++;
70+
if (numOnes == 30) {
71+
inKey=0;
72+
numOnes=0;
73+
Serial.println("END");
74+
delay(500);
75+
}
4876
} else {
49-
theKey = (theKey>>1);
50-
numOnes = 0;
51-
// Serial.print(", 0, ");
52-
//Serial.print(0);
77+
numOnes=0;
78+
Serial.println("0");
5379
}
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]);
6180
}
62-
Serial.println(")");
63-
digitalWrite(LED_BUILTIN, LOW);
64-
// Serial.println("END");
6581
}
6682
}

0 commit comments

Comments
 (0)