
28 Make: Robotic Arms
STEP 3
Now that we are able to read the values coming from our potentiometer, as
well as store the values in a variable, the next thing we need to do is scale
the numbers to a more usable range. Keep in mind that the potentiometer
is looking for an input number from 0 to 180, so the data as we have it now
won’t be super useful to us. Thankfully, there exists the perfect solution: the
map() command, which will allow us to scale the range of numbers from
the potentiometer into a more useful range. Let’s remix our code, adding the
map() command:
#include <Servo.h>
int pos;
void setup() {
Serial.begin(9600);
}
void loop() {
pos =