5,710
edits
Changes
→Moving a Servo
== Moving a Servo ==
// potentiometer_servo // turning the knob turns the servo // Robert Twomey - roberttwomey.com #include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int a_in = 0; // analog in pin int val = 0; // variable to store analog value
int pos = 0; // variable to store the servo position int delay_time = 15; void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }
void loop() { val=analogRead(a_in); // read value from potentiometer pos=map(val, 0, 1023, 0, 180); // map 0-1023 value to 0-180 degrees myservo.write(pos); // set servo position
== Homework ==
ASSIGNMENT: