#include <Servo.h>
Servo servo1;
Servo servo2;
int pushButton = 2;
int z;
int buttonState = 0;
int zState = 0;
void setup()
{
pinMode(pushButton, INPUT);
servo1.attach(9);
servo2.attach(10);
}
void loop()
{
initial();
delay(2000);
same_degree();
delay(2000);
buttonState = digitalRead(pushButton);
if(buttonState == HIGH)
{
zState = 1 - zState;
}
if(zState == 1)
{
servo2.write(0);
delay(2000);
servo2.write(180);
delay(2000);
}
}
void initial()
{
servo1.write(0);
}
void same_degree()
{
servo1.write(180);
}
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/) | Powered by Discuz! X3.2 |