bool time = false; double startTime=millis(); void setup() { Serial.begin(9600); // put your setup code here, to run once: pinMode(1,INPUT); pinMode(16,INPUT); pinMode(9,OUTPUT); } void loop() { // put your main code here, to run repeatedly: if (millis() > startTime+5000){ time=true; } if (time == true){ digitalWrite(9,HIGH); if (digitalRead(1) == HIGH){ Serial.print('a'); time=false; digitalWrite(9,LOW); startTime=millis(); } else if (digitalRead(16) == HIGH){ Serial.print('b'); time=false; digitalWrite(9,LOW); startTime=millis(); } } }