İki buton ile servo motor kontrolü
#include
Servo myservo;
int pos = 0;
int buton1=2; // buton1, 2 nolu pine bağlanacak
int buton2=3; // buton2, 3 nolu pine bağlanacak
void setup()
{
myservo.attach(5); // servonun data ucu 5 nolu pine takılacak.İstediğiniz pine takabilirsiniz.
pinMode(buton1,INPUT);
pinMode(buton2,INPUT);
}
void loop()
{
if (digitalRead(buton1)==0&&(pos<180))
// buton1 e basılmışsa ve motor en sağa ulaşmamışsa
{ // buton basılı olduğu sürece sağa döner
pos=pos+1;
myservo.write(pos);
delay(5); // bu değer düşürülerek daha hızlı döndürülebilir
}
if (digitalRead(buton2)==0&&(pos>0))
// buton2 ye basılmışsa ve motor en sola ulaşmamışsa
{ // buton basılı olduğu sürece sola döner
pos=pos-1;
myservo.write(pos);
delay(5);
}
}