# Lesson 2.?: Binding Commands to Triggers

Accompanying code lesson: TODO

There are 6 methods that each schedule/cancel a command depending on how the state changes: `onFalse()`, `onTrue()`, `toggleOnFalse()`, `toggleOnTrue()`, `whileFalse()`, and `whileTrue()` . Each methods' behaviors are shown in the diagram below:

<figure><img src="/files/JX0RyqVjQ8tqMqVs9NvD" alt=""><figcaption><p>How each binding method behave based on when the boolean state flips true or flips false. Based on a diagram by BoVLB.</p></figcaption></figure>

The syntax for binding a `Command` to a `Trigger` is as follows:

```java
trigger.whileTrue(subsystem.command())
```

For binding to a controller button, the syntax is as follows:

```java
controller.a().whileTrue(subsystem.command())
```

Code examples:

* Kernel Overflow (Team 167, Reefscape)
  * [Primary driver controls](https://github.com/icrobotics-team167/2025_Reefscape/blob/230afa18a2fbffd82682add448cd1f2adc900073/src/main/java/frc/cotc/Robot.java#L169-L182)
* Croppenheimer (Team 167, Crescendo)
  * [Secondary driver controls](https://github.com/icrobotics-team167/2024_Crescendo/blob/b1898be3392ba71757261eedc3181955ea389f3b/src/main/java/frc/robot/RobotContainer.java#L220-L231)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iowacityrobotics.org/programming/frc-programming/section-2-commands/lesson-2.-binding-commands-to-triggers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
