//ณัฐกิจ เล็กชิน เลขที่13 ปวส.2/1
int sw1=0,sw2=0,locksw1=0,locksw2=0;
int relay1=13,relay2=12;
int start_m=0,rotate_m=0;
void setup() {
Serial.begin(115200);
pinMode(5, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
}
void loop() {
sw1 = digitalRead(5);
sw2 = digitalRead(18);
if((sw1==0)&&(locksw1==0)){
start_m++;
locksw1=1;
if(start_m>1){
start_m=0;
}
}
else if((sw1==1)&&(locksw1==1)){
locksw1=0;
}
if((sw2==0)&&(locksw2==0)){
rotate_m++;
locksw2=1;
if(rotate_m>1){
rotate_m=0;
}
}
else if((sw2==1)&&(locksw2==1)){
locksw2=0;
}
if(start_m==1){
if(rotate_m==1 ){
digitalWrite(relay1, HIGH);
digitalWrite(relay2,LOW);
}
else{
digitalWrite(relay1, LOW);
digitalWrite(relay2,HIGH);
}
}
else{
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
}
Serial.print(start_m);
Serial.print("\t");
Serial.println(rotate_m);
}