i have a led light that i am turning on for 4 seconds with a switch. the switch only stays closed for a fraction of a second. the delay function works but it shuts down all processing and i can't have that.
does anyone know how to substitute the millis function for the delay function?
here's the code that works and compiles except for the delay function issue.
void setup() {
Serial.begin(9600);
}
// put your main code here, to run repeatedly:
void loop() {
pinMode(2, INPUT_PULLUP);
int sensorVal = digitalRead(2);
Serial.println(sensorVal);
delay (10);
pinMode(7, OUTPUT);// initialize digital pin 7 as an output.
if (sensorVal == HIGH) {
digitalWrite(7, LOW);
delay(4000);
}
else {
digitalWrite(7, HIGH);
i need the led light to stay on for 4 seconds even though the switch is not being closed. also, i want the 4 seconds to reset if the arduino sees the switch closed before the 4 seconds has passed. if arduino does not the switch closed after 4 seconds, the the light should go off.
thanks to everyone that replied.