Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to include the Servo library.
Arduino
#include [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes instead of angle brackets
Misspelling the library name
Using lowercase letters in the filename
✗ Incorrect
The Servo library is included with #include <Servo.h> to control servo motors.
2fill in blank
mediumComplete the code to attach the servo to pin 9.
Arduino
servo.[1](9);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using connect() instead of attach()
Using begin() or start() which are not servo methods
✗ Incorrect
The attach() method connects the servo object to the specified pin.
3fill in blank
hardFix the error in the code to write 90 degrees to the servo.
Arduino
servo.[1](90);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using writeAngle() or setAngle() which do not exist
Using move() which is not a Servo method
✗ Incorrect
The correct method to set the servo angle is write().
4fill in blank
hardFill both blanks to create a loop that moves the servo from 0 to 180 degrees in steps of 30.
Arduino
for (int angle = [1]; angle <= [2]; angle += 30) { servo.write(angle); delay(500); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 90 as start or end angle
Using 360 which is beyond servo range
✗ Incorrect
The loop starts at 0 degrees and goes up to 180 degrees to cover the servo's range.
5fill in blank
hardFill all three blanks to create a dictionary-like mapping of angles to delay times and move the servo only if delay is greater than 300 ms.
Arduino
int delays[] = {100, 400, 600};
for (int i = 0; i < 3; i++) {
int angle = [1];
int delayTime = delays[i];
if (delayTime [2] 300) {
servo.[3](angle);
delay(delayTime);
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' for angle calculation
Using '<' instead of '>' in the if condition
Using move() instead of write() for servo
✗ Incorrect
We calculate angle as i*60, check if delayTime > 300, and use write() to move the servo.
