#include <Servo.h>
Servo myservo;
void setup() {
//Serial.begin(115200);
// put your setup code here, to run once:
pinMode(6,OUTPUT);
pinMode(12,INPUT);
pinMode(11,INPUT);
pinMode(13,OUTPUT);
myservo.attach(10);
}
unsigned long tl=0, tb=0;
const long i=1000;
boolean c=0;
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(11)||digitalRead(12)){
myservo.write(90);
tb=millis();
if(tb-tl>=i){
tl=tb;
c=!c;
}
if (c==1){
tone(6,450);
delay(10);
digitalWrite(13,HIGH);
}
else {
tone(6,670);
delay(10);
digitalWrite(13,LOW);
}/*
Serial.print("tb: ");
Serial.print(tb);
Serial.print("\t tl:");
Serial.println(tl);*/
}
else{
noTone(6);
myservo.write(0);
digitalWrite(13,LOW);
}
}