Why does the loop stop when dutyCycle is 120 even though we set it to 100 in the last step?
The loop condition checks if dutyCycle <= 100 before running the loop body. When dutyCycle becomes 120 after adding 20, the condition fails and the loop stops, as shown in execution_table step 7.
What does setPWM(dutyCycle) do in this code?
setPWM(dutyCycle) sets the PWM signal's duty cycle, controlling how long the signal is ON versus OFF, which changes the brightness or motor speed. This is the key action in each loop step (see execution_table Action column).
Why do we add 20 to dutyCycle each time?
Adding 20 increases the duty cycle in steps, making the LED or motor gradually brighter or faster. This step size controls how smooth or fast the change happens, as seen in variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the dutyCycle value at step 4?
A60
B40
C80
D100
💡 Hint
Check the dutyCycle column in execution_table row 4.
At which step does the loop condition become false and stop the loop?
AStep 5
BStep 6
CStep 7
DStep 3
💡 Hint
Look at the Condition and Action columns in execution_table row 7.
If we change the increment from 20 to 10, how would the variable_tracker change?
AdutyCycle would stay the same
BdutyCycle would increase by 10 each step instead of 20
CdutyCycle would decrease each step
DdutyCycle would jump directly to 100
💡 Hint
Check how dutyCycle changes in variable_tracker and think about changing the increment.
Concept Snapshot
Duty cycle controls ON time in PWM signal.
Higher duty cycle means brighter LED or faster motor.
Use a loop to change duty cycle gradually.
setPWM(dutyCycle) applies the PWM signal.
Loop stops when dutyCycle exceeds max value.
Full Transcript
This example shows how to control a motor or LED brightness using PWM duty cycle in embedded C. The program starts with dutyCycle at 0 and increases it by 20 each loop iteration. Each step sets the PWM signal with setPWM(dutyCycle), waits 100 milliseconds, then increases dutyCycle. The loop stops when dutyCycle exceeds 100. The execution table traces each step, showing variable values and actions. Key moments explain why the loop stops and what setPWM does. The visual quiz tests understanding of dutyCycle values and loop behavior. The concept snapshot summarizes how duty cycle affects brightness or speed.