1
1
/*
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.
8
4
*/
9
5
10
- const int buttonPin = 7 ; // the number of the pushbutton pin
11
6
const int dataPin = 2 ; // corresponds to pin 6 on the KB connector (and pin 6 of the RJ12)
12
7
const int resetPin = 5 ; // corresponds to pin 2 on the KB connector (and pin 4 on the RJ12)
13
8
14
- int buttonState = 0 ; // variable for reading the pushbutton status
9
+ int changed = 0 ;
15
10
16
11
void setup () {
17
12
pinMode (LED_BUILTIN, OUTPUT);
18
- pinMode (buttonPin, INPUT);
19
13
pinMode (resetPin, OUTPUT);
20
14
pinMode (dataPin, INPUT);
21
15
@@ -28,57 +22,32 @@ void setup() {
28
22
Serial.println (" Hello logic_analyzer" );
29
23
}
30
24
31
- int changed = 0 ;
32
- int shouldRead = 0 ;
33
25
int data = 0 ;
34
26
int inKey = 0 ; // are we reading a key?
35
27
int numOnes = 0 ; // the # of 1s in a row
36
28
37
29
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 " );
44
36
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 );
81
47
}
48
+ } else {
49
+ numOnes = 0 ;
50
+ Serial.println (" 0" );
82
51
}
83
52
}
84
53
}
0 commit comments