int servo = 3;
int pb = 5;
void setup()
{
pinMode(servo, OUTPUT);
pinMode(pb, INPUT);
}
void loop()
{
int cur;
int pos= 0;
int rd = digitalRead(pb);
if (rd == HIGH)
{
cur = pos +1;
pwmpos(cur,servo);
}
else
{
pwmpos(cur,servo);
}
}
void pwmpos(int x,int y)
{
float ang = (x*10.66)+500;
digitalWrite(y,HIGH);
delayMicroseconds(ang);
digitalWrite(y,LOW);
delayMicroseconds(20000);
}//1460
/*for( int i = 0;i <=50;i++)
{
digitalWrite(servo,HIGH);
delayMicroseconds(500);
digitalWrite(servo,LOW);
delayMicroseconds(20000);
}//0
delay(1500);
for( int i = 0;i <=50;i++)
{
digitalWrite(servo,HIGH);
delayMicroseconds(1460);
digitalWrite(servo,LOW);
delayMicroseconds(20000);
}//90 18540
delay(1500);
for( int i = 0;i <=50;i++)
{
digitalWrite(servo,HIGH);
delayMicroseconds(2352);
digitalWrite(servo,LOW);
delayMicroseconds(20000);
}//180 17648
delay(1500);*/