Bird
0
0
Arduinoprogramming~10 mins

Servo angle positioning in Arduino - Interactive Code Practice

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

Complete the code to include the Servo library.

Arduino
#include [1]
Drag options to blanks, or click blank then click option'
A<Servo.h>
B<Servo>
C"Servo.h"
D<servo.h>
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes instead of angle brackets
Misspelling the library name
Using lowercase letters in the filename
2fill in blank
medium

Complete the code to attach the servo to pin 9.

Arduino
servo.[1](9);
Drag options to blanks, or click blank then click option'
Aconnect
Bstart
Cbegin
Dattach
Attempts:
3 left
💡 Hint
Common Mistakes
Using connect() instead of attach()
Using begin() or start() which are not servo methods
3fill in blank
hard

Fix 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'
AwriteAngle
Bwrite
CsetAngle
Dmove
Attempts:
3 left
💡 Hint
Common Mistakes
Using writeAngle() or setAngle() which do not exist
Using move() which is not a Servo method
4fill in blank
hard

Fill 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'
A0
B180
C90
D360
Attempts:
3 left
💡 Hint
Common Mistakes
Using 90 as start or end angle
Using 360 which is beyond servo range
5fill in blank
hard

Fill 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'
Ai * 60
B>
Cwrite
Di + 30
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