Skip to content

Commit bdebe01

Browse files
committed
Removed all the button start/stop logic
1 parent 9815615 commit bdebe01

File tree

1 file changed

+22
-53
lines changed

1 file changed

+22
-53
lines changed
Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
/*
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.
6-
*
7-
* Based on http://www.arduino.cc/en/Tutorial/Button
2+
Simple logic analyzer. Triggers when the data pin goes low.
3+
Records bits until 30 1's in a row are received.
84
*/
95

10-
const int buttonPin = 7; // the number of the pushbutton pin
116
const int dataPin = 2; // corresponds to pin 6 on the KB connector (and pin 6 of the RJ12)
127
const int resetPin = 5; // corresponds to pin 2 on the KB connector (and pin 4 on the RJ12)
138

14-
int buttonState = 0; // variable for reading the pushbutton status
9+
int changed = 0;
1510

1611
void setup() {
1712
pinMode(LED_BUILTIN, OUTPUT);
18-
pinMode(buttonPin, INPUT);
1913
pinMode(resetPin, OUTPUT);
2014
pinMode(dataPin, INPUT);
2115

@@ -28,57 +22,32 @@ void setup() {
2822
Serial.println("Hello logic_analyzer");
2923
}
3024

31-
int changed = 0;
32-
int shouldRead = 0;
3325
int data = 0;
3426
int inKey = 0; // are we reading a key?
3527
int numOnes = 0; // the # of 1s in a row
3628

3729
void loop() {
38-
// read the state of the pushbutton value:
39-
buttonState = digitalRead(buttonPin);
40-
41-
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
42-
if (buttonState == HIGH && !changed) {
43-
// turn LED on, and toggle recording.
30+
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.println("0");
4436
digitalWrite(LED_BUILTIN, HIGH);
45-
Serial.println("on");
46-
shouldRead = 1 - shouldRead;
47-
Serial.print("ShouldRead is "); Serial.println(shouldRead);
48-
changed = 1;
49-
} else if (buttonState == LOW && changed) {
50-
// turn LED off:
51-
digitalWrite(LED_BUILTIN, LOW);
52-
Serial.println("off");
53-
changed = 0;
54-
55-
// beep/reset, and keep reading.
56-
digitalWrite(resetPin , LOW);
57-
delay(10);
58-
digitalWrite(resetPin , HIGH);
59-
}
60-
61-
if (shouldRead == 1) {
62-
data = digitalRead(dataPin);
63-
if (data == LOW && !inKey) {
64-
inKey=1; // we're recording until numones==30
65-
numOnes=0;
66-
Serial.println("START");
67-
Serial.println("0");
68-
} else if (inKey) {
69-
if (data == HIGH) {
70-
Serial.println("1");
71-
numOnes++;
72-
if (numOnes == 30) {
73-
inKey=0;
74-
numOnes=0;
75-
Serial.println("END");
76-
delay(500);
77-
}
78-
} else {
79-
numOnes=0;
80-
Serial.println("0");
37+
} else if (inKey) {
38+
if (data == HIGH) {
39+
Serial.println("1");
40+
numOnes++;
41+
if (numOnes == 30) {
42+
inKey = 0;
43+
numOnes = 0;
44+
digitalWrite(LED_BUILTIN, LOW);
45+
Serial.println("END");
46+
delay(500);
8147
}
48+
} else {
49+
numOnes = 0;
50+
Serial.println("0");
8251
}
8352
}
8453
}

0 commit comments

Comments
 (0)