-
Type “myservo.write(0);” between the curly brackets ({ and }) of the loop function.
STEM Connections
You will soon build a circuit using a standard Servo. Remember, a standard Servo can move to any angle in a half circle (from 0° to 180°) and remain there until instructed to move again. Standard Servos are very helpful if you want a mechanism that moves to specific angles.
This line of code contains a function known as the “write” function. For standard Servos, the number inside the parenthesis of the write function determines the angle to which the Servo moves. In this case, the number you wrote in the code was 0, and so this line of code tells the standard Servo to move to 0°. This may look different between two Servos because of how the Servo horn was attached, but when you instruct your Servo to move to 0°, it will always return to the same place.
The write function will have a different effect on the continuous Servo, but we will explore that more in later steps.
This function is written inside the curly brackets of the void loop so that it will be repeated.
At the Thinkabit Lab, we emphasize that the void loop is where “all the action happens,” as follows:
-
Explain that this is where “we tell the Servo what to do.”
-
Remind students that in the LED Blink code the line “digitalWrite (13,HIGH);” executed an action. Likewise, this line of code “myservo.write(0);” will cause the Servo to move. The number inside the parentheses, called the parameter, controls the movement of the Servo. The parameter of 0 will cause the standard Servo to move to position 0°.
-
Explain that this line of code is an example of how coding is related to English. In English classes, students typically read and write. When they read, they are inputting information, and when they write, they are outputting information. The code speaks a similar language. When it is outputting information it uses the command “write” and when it is inputting information, it uses the command “read”.
-
Remind students that they won’t use the read command unless they start using sensors.
If you are using the Thinkabit Lab Notebook:
Have students fill in the next blank on page 15:
myservo.write(0); Servo action '0'
Explain to students that this action varies depending on which Servo we are using. Alternatively, you could write "small Servo to 0°, big Servo spin fast left"
Alternatively, you can write the entire code on the computer and fill in the notebook at the end.
‘write’ didn’t turn orange
-
Check the spelling of the word “write” and make sure that no letters are capitalized.
-
Check that there is a period between “myservo” and “write”.
-
Check that there is a semicolon after “myservo.write(0)”.
-
If it changed colors to a different color, the Arduino software may have been updated. As long as it is colored, the code should still work properly.