One-Button Behavior Switching
One-Button Behavior Switching
animation
sensors
braitenberg
One-Button Behavior Switching
With the design decision made, return to the wiring itself. A one-button mode switch is a compact way to test whether you can predict behavior before watching the robot move.
This exercise switches a Braitenberg vehicle between fear, aggression, and love modes using a button. Focus on how wiring topology changes behavior:
The mode-switching controller has one repeated loop:
- Read the button; if pressed, rotate through Fear, Aggression, and Love modes.
- Read the left and right light sensors.
- Apply the selected wiring rule:
- Fear: left sensor -> left motor, right sensor -> right motor.
- Aggression: left sensor -> right motor, right sensor -> left motor.
- Love: stronger light reduces the same-side motor speed.
- Update both motor PWM values and repeat at about 20 Hz.
The important learning point is the mapping, not the boilerplate pin setup.
Behavior observations when testing:
| Mode | Flashlight on left | Flashlight on right | Flashlight centered |
|---|---|---|---|
| Fear | Turns right (away) | Turns left (away) | Drives straight ahead fast |
| Aggression | Turns left (toward) | Turns right (toward) | Drives straight into light |
| Love | Turns left (toward) slowly | Turns right (toward) slowly | Slows down, stops near light |