bool numberDefined; int second; void setup() { pinMode(0, INPUT); pinMode(1, OUTPUT); Serial.begin(9600); numberDefined = false; second = 0; } void loop() { if (Serial.available()) { int var = Serial.read(); int val = var - 0x30; if (val >= 0 && val < 9) { Serial.print("LED will glow "); Serial.print(val); Serial.println(" seconds."); second = val; numberDefined = true; } } int state = digitalRead(0); if (state == LOW) { if (numberDefined == true) { Serial.println("Button Pressed"); digitalWrite(1, HIGH); delay(1000 * second); digitalWrite(1, LOW); delay(100); numberDefined = false; Serial.println("You can set another time"); } else { Serial.println("Glow time is not defined"); delay(1000); } } else digitalWrite(1, LOW); }