#include <Servo.h>
Servo servo1;
int pos = 0;
void setup()
{
Serial.begin(9600); // setup serial
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
servo1.attach(10);
servo1.write(0);
}
void loop()
{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
for (int i = 0; i < 7000; i++)
{
delay(1);
if (digitalRead(9) == 1)
{
delay(300);
pos = pos - 36;
if (pos < 0) {pos = 0;}
servo1.write(pos);
i = 7001;
}
}
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
for (int i = 0; i < 7000; i++)
{
delay(1);
if (digitalRead(9) == 1)
{
delay(300);
pos = pos + 36;
if (pos > 180) {pos = 180;}
servo1.write(pos);
i = 7001;
}
}
}
No comments:
Post a Comment