Creating a project with a servo and a sensor
Let's start with just a servo and the REPL, then we can add in a sensor. Use the diagram from the previous section as a reference to wire up a servo, and use pin 6 for signal.
Before we write our program, let's take a look at some of the options the Servo
object constructor gives us. You can set an arbitrary range by passing [min, max]
to the range
property. This is great for low quality servos that have trouble at very low and very high values.
The type
property is also important. We'll be using a standard servo, but you'll need to set this to continuous
if you're using a continuous servo. Since standard
is the default, we can leave this out for now.
The offset
property is important for calibration. If your servo is set too far in one direction, you can change the offset to make sure it can programmatically reach every angle it was meant to. If you hear clicking at very high or low values, try adjusting the offset.
You can invert the direction of...