millisを使いたくて以下のプログラムを作成したのですが上手く動きません。
改善点を是非教えてほしいです。
#include<Servo.h>
Servo myservo;
Servo myservo2;
Servo myservo3;
int pos=0;
int flag=0;
int sw1=1;
long beforetime = 0;
void setup(){
myservo.attach(9);
myservo2.attach(10);
myservo3.attach(11);
pinMode(13, OUTPUT);
}
void loop()
{
flag=digitalRead(sw1);
if(millis() - beforetime > 5000){
for( pos=0 ;pos<=180; pos=pos+1){
myservo.write(180-pos);
myservo2.write(180-pos);
myservo3.write(180-pos);
}
for( pos=180 ;pos>=0; pos-=1){
myservo.write(180-pos);
myservo2.write(180-pos);
myservo3.write(180-pos);
}
}
else{
}
}