if (digitalRead(indR)) { i=0; //if indicators were reversed, the cycle needs to be reset to full 5s while(digitalRead(indR) && i<100) { i++; digitalWrite(fogR, HIGH); digitalWrite(fogL, LOW); delay(50); } } if (digitalRead(indL)) { //same as right side i = 0; while(digitalRead(indL) && i<100) { i++; digitalWrite(fogR, LOW); digitalWrite(fogL, HIGH); delay(50); } } if (!digitalRead(indR) && !digitalRead(indL)) // no indicators currently on if (i == 100) { //neither indicators were on OR the 5s cycle is over digitalWrite(fogR, LOW); digitalWrite(fogL, LOW); } else //one or both indicators were on for less than 5s while(!digitalRead(indR) && !digitalRead(indL) && i<100) { //but not any more i++; //finish the 5s cycle in the last foglight configuration delay(50); }}