WEBVTT

00:00.000 --> 00:05.880
You already know the difference between a button being held, pressed, and released.

00:05.880 --> 00:13.160
Let's trace the same button across five robot loops so we can see exactly when each signal becomes true.

00:13.160 --> 00:16.240
Each column represents one pass through the robot loop.

00:16.240 --> 00:20.280
The button values are false, false, true, true, and false.

00:20.280 --> 00:25.080
The button remains down for loops three and four, so the loop reads true twice.

00:25.080 --> 00:34.600
That does not mean the driver pressed it twice. The program sampled the same held button on two different loops.

00:34.600 --> 00:41.880
If we draw these values as a graph, the line starts low because the button is false during loops one and two.

00:41.880 --> 00:49.260
Before loop three, the line steps straight up. That rising edge is the instant the button becomes pressed.

00:49.260 --> 00:56.160
The line stays high through loops three and four. That flat high section means the button is being held.

00:56.160 --> 00:58.800
It does not create another press.

00:58.800 --> 01:05.320
Before loop five, the line steps straight back down. That falling edge is the release.

01:05.320 --> 01:08.520
The line remains low because the button is false again.

01:08.520 --> 01:14.760
This looks like one square pulse from a PWM-style graph, but it is not a PWM output.

01:14.760 --> 01:20.400
We are only using the shape to show a boolean button state over time.

01:20.400 --> 01:25.240
Now we can compare the current sample with the previous sample.

01:25.240 --> 01:32.680
Held is the current button value, so it is true on both loops where the button is down.

01:32.680 --> 01:38.240
A pressed signal, also called a rising edge, is true only on loop three.

01:38.240 --> 01:42.440
That is the moment current changes from false to true.

01:42.440 --> 01:51.200
A released signal, or falling edge, is true only on loop five, where current changes from true back to false.

01:51.200 --> 01:59.480
At the top of the loop, `currentA` reads the button now.

01:59.480 --> 02:04.360
`previousA` still contains the value from the last loop.

02:04.360 --> 02:13.480
`aPressed` is true when current is true and previous is false, so it is the rising edge.

02:13.480 --> 02:18.840
`aReleased` is true when current is false and previous is true, so it is the falling edge.

02:18.840 --> 02:24.860
The order matters here, and we calculate both edges first.

02:24.860 --> 02:33.440
Update `previousA` near the bottom of the loop, after the results have already been used.

02:33.440 --> 02:41.560
If you overwrite previous before then, both values become identical and the edge disappears.

02:41.560 --> 02:51.200
The slow-mode line reads `left_bumper` directly because slow mode should remain active while the bumper is held.

02:51.200 --> 03:00.400
The claw toggle uses `aPressed` because the claw should change once per button press, not repeatedly while held.

03:00.400 --> 03:08.440
Without a rising-edge detector, the toggle would only work if the driver pressed the button for exactly one sample.

03:08.440 --> 03:14.320
That is not reliable or realistic.

03:14.320 --> 03:23.240
While held uses the current value.

03:23.240 --> 03:28.200
When pressed uses the rising edge, and when released uses the falling edge.

03:28.200 --> 03:38.840
Edge detection cannot fix a confusing control layout, so talk with your drivers before writing the condition.

03:38.840 --> 03:46.840
Before running the code, complete the held, pressed, and released rows for these five samples.

03:46.840 --> 03:57.560
Choose one season-robot action that should repeat while held and one action that should happen when pressed.

03:57.560 --> 04:11.240
Predict first, compare with telemetry, and document the controls so new drivers know how they work after the season ends.
