#define LED 4 #define BUTTON 2 bool _IsRunning = false; bool _LightIsOn = false; long _RandomTime = 0; void setup() { // put your setup code here, to run once: pinMode(LED, OUTPUT); pinMode(BUTTON, INPUT); randomSeed(analogRead(0)); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: if(!_IsRunning) { Serial.println("Not Running"); if(!_LightIsOn) { Serial.println("Light Is On"); _LightIsOn = true; digitalWrite(LED, HIGH); } if(digitalRead(BUTTON) == LOW) { Serial.println("Button Pressed"); _RandomTime = random(2000,30000); _LightIsOn = false; _IsRunning = true; digitalWrite(LED, LOW); } } else { Serial.println("Running"); delay(_RandomTime); _IsRunning = false; } }