Code Challenge

Code Challenge

animation
sensors
braitenberg
Try Choose left_motor = PWM(25) for blank 1 and right_motor.duty(left) for blank 2.
Observe Compare the feedback with the fixed lines: ADC(34) and ADC(35) read the sensors, while PWM(25) and PWM(26) define the motors.
Explain The accepted lines make the value read from ADC(34) drive PWM(26), while the opposite sensor value drives PWM(25).

Technical boundaries. This exercise assumes the shown cross-wiring rule and checks fixed answer choices. It does not run a vehicle simulation or scale ADC readings to a PWM duty range.

Code Challenge

Treat the missing lines as a signal-path test, not a syntax puzzle. The first blank must create a PWM output for the left motor; an ADC or input constructor would put that pin on the sensing side of the system. For the second blank, keep the cross-coupling explicit: the value named left came from left_sensor, so writing it to right_motor makes the vehicle turn toward the brighter side rather than merely changing both motors together. After filling both gaps, trace the complementary final line—left_motor.duty(right)—to confirm that each sensor controls the opposite wheel. The challenge therefore checks the mechanism behind Vehicle 2b attraction and reconnects the code to the emergent-behaviour discussion, where a simple wiring rule produces the motion without a stored path plan.

Back to the chapter