Anda di halaman 1dari 1

servo 2

#include <Servo.h>
//////////////untuk kaki 2////////////////////
Servo kaki1;
Servo kaki2;
int nilaikaki1,nilaikaki2,pos1,pos2;
void setup()
{
kaki1.attach(3); // attaches the servo on pin 9 to the servo object
kaki2.attach(5);
nilaikaki1=90;//diisi sendiri
nilaikaki2=90;//diisi sendiri
}
void loop()
{
//pos1-60
pos1=nilaikaki1+30;
pos2=nilaikaki2-30;
for(;pos1>=nilaikaki1-30;pos1--,pos2++) // goes from 0 degrees to 180 degrees
{
// in steps of 1 degree
kaki1.write(pos1);
kaki2.write(pos2);
delay(10);
}
//pos1+60
for(; pos1<=nilaikaki1+30; pos1++,pos2--)
// goes from 180 degrees to 0 de
grees
{
kaki1.write(pos1);
kaki2.write(pos2);
delay(10);
}
}