0
0
Embedded Cprogramming~10 mins

Duty cycle control for motor/LED in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the PWM duty cycle to 50%.

Embedded C
PWM_SetDutyCycle([1]);
Drag options to blanks, or click blank then click option'
A0
B255
C128
D64
Attempts:
3 left
💡 Hint
Common Mistakes
Using 255 sets the duty cycle to 100%, not 50%.
Using 0 turns the output off.
2fill in blank
medium

Complete the code to increase the duty cycle by 10%.

Embedded C
dutyCycle = dutyCycle + [1];
Drag options to blanks, or click blank then click option'
A26
B25
C10
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 increases duty cycle by too little.
Using 25 is close but less accurate.
3fill in blank
hard

Fix the error in the code to prevent duty cycle overflow.

Embedded C
if (dutyCycle [1] 255) {
    dutyCycle = 255;
}
Drag options to blanks, or click blank then click option'
A>=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' causes off-by-one error.
Using '<' or '==' does not prevent overflow.
4fill in blank
hard

Fill both blanks to create a dictionary that maps LED names to their duty cycles if duty cycle is above 100.

Embedded C
ledDutyCycles = { [1]: [2] for [1] in leds if [2] > 100 }
Drag options to blanks, or click blank then click option'
Aled
BdutyCycle
Cleds[led]
DledDutyCycles
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dutyCycle' as key or value is incorrect.
Using 'ledDutyCycles' inside comprehension causes error.
5fill in blank
hard

Fill all three blanks to create a dictionary of LEDs with duty cycles above 150, converting LED names to uppercase.

Embedded C
highDuty = { [1]: [2] for [3] in leds if [2] > 150 }
Drag options to blanks, or click blank then click option'
Aled.upper()
Bleds[led]
Cled
DdutyCycle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dutyCycle' as loop variable is wrong.
Not converting LED names to uppercase.