Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start the motor by setting the pin HIGH.
Arduino
digitalWrite(motorPin, [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH to start the motor.
✗ Incorrect
Setting the motor pin to HIGH turns the motor on by providing voltage.
2fill in blank
mediumComplete the code to set the motor pin as an output.
Arduino
pinMode(motorPin, [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting pinMode to INPUT instead of OUTPUT.
✗ Incorrect
To control a motor, the pin must be set as OUTPUT to send signals.
3fill in blank
hardFix the error in the code to stop the motor by setting the pin LOW.
Arduino
digitalWrite(motorPin, [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using HIGH instead of LOW to stop the motor.
✗ Incorrect
Setting the motor pin to LOW stops the motor by cutting off voltage.
4fill in blank
hardFill both blanks to control motor speed using PWM.
Arduino
analogWrite(motorPin, [1]); // speed value between 0 and [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1023 which is for analogRead, not analogWrite.
✗ Incorrect
Speed values start at 0 (off) and go up to 255 for full speed in Arduino PWM.
5fill in blank
hardFill all three blanks to create a dictionary of motor speeds for different directions.
Arduino
motorSpeeds = [1]: 255, [2]: 0, [3]: 128}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as keys instead of strings.
✗ Incorrect
This dictionary maps directions to speed values: full speed forward, stop, and half speed.
