PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
libArduino
tests
AnalogInput
AnalogInput.cpp
1
// Controlling a servo position using a potentiometer (variable resistor)
2
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
3
4
#include <Arduino.h>
// The only thing I added
5
#include <Servo.h>
6
7
Servo
myservo;
// create servo object to control a servo
8
9
int
potpin = 0;
// analog pin used to connect the potentiometer
10
int
val;
// variable to read the value from the analog pin
11
12
void
setup()
13
{
14
myservo.attach(9);
// attaches the servo on pin 9 to the servo object
15
}
16
17
void
loop()
18
{
19
val = analogRead(potpin);
// reads the value of the potentiometer (value between 0 and 1023)
20
val = map(val, 0, 1023, 0, 179);
// scale it to use it with the servo (value between 0 and 180)
21
myservo.write(val);
// sets the servo position according to the scaled value
22
delay(15);
// waits for the servo to get there
23
}
Servo
Definition:
Servo.h:41
Generated on Fri May 20 2022 16:48:01 for PropWare by
1.8.17