Skip to content

Commit fd706e6

Browse files
committed
Start reading the scope after a falling trigger
1 parent 9c5b09f commit fd706e6

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

scope/scope.ino

+39-11
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,51 @@
22

33
// potentiometer wiper (middle terminal) connected to analog pin 3
44
// outside leads to ground and +5V
5-
int analogPin = A3;
5+
int analogPin = A3;
6+
// Pin to trigger
7+
const int triggerPin = 2;
8+
9+
int trigger = 0;
610
int val = 0; // variable to store the value read
11+
int shouldRead = 0;
12+
int ones = 0;
713

814
void setup() {
9-
Serial.begin(9600);
10-
Serial.println("Hello scope");
15+
pinMode(triggerPin, INPUT);
16+
17+
Serial.begin(1000000);
18+
Serial.println("Hello trigger scope");
1119
}
1220

1321
void loop() {
14-
// read the analog port
15-
// send back to the result as an appropriately formatted string
16-
val = analogRead(analogPin); // read the input pin
22+
trigger = digitalRead(triggerPin);
23+
if (!shouldRead && trigger == LOW) {
24+
Serial.println("triggered");
25+
shouldRead = 1;
26+
ones = 0;
27+
}
28+
if (shouldRead) {
29+
Serial.print("kb "); Serial.print(trigger); Serial.print(" Analog: ");
30+
}
31+
if (shouldRead && trigger == HIGH) {
32+
// Stop reading after 30 ones in a row.
33+
ones++;
34+
if (ones == 300) {
35+
Serial.println("untriggered");
36+
shouldRead = 0;
37+
}
38+
}
39+
if (shouldRead) {
40+
// read the analog port
41+
// send back to the result as an appropriately formatted string
42+
val = analogRead(analogPin); // read the input pin
1743

18-
// Scale to 80 chars wide, assuming a 10bit A/D
19-
int width=80*(val/1024.0);
20-
for (int x = 0; x < width; ++x) {
21-
Serial.print(" ");
44+
// Scale to 80 chars wide, assuming a 10bit A/D
45+
int width = 80 * (val / 1024.0);
46+
for (int x = 0; x < width; ++x) {
47+
Serial.print(" ");
48+
}
49+
Serial.print("* ");
50+
Serial.println(5.0*val/1024); // debug value
2251
}
23-
Serial.println(val); // debug value
2452
}

0 commit comments

Comments
 (0)