stop led in a void

This is a very simple code, I am stuck with how I can change the string from HIGH to LOW on an LED on a given amount of seconds. I tried doing a delay, but the delay didn't seem to be working properly. Ideally, as soon as my wheelspeedpin2 goes high, I want the LED to flash or stay on a few seconds indicating that the signal has changed, then going back to "wait" mode. so that when wheelspeedpin3 goes high, it does the same.

const int led = 13; const int WheelSpeedPin2 = 2; const int WheelSpeedPin3 = 3;

void setup() { pinMode(led, OUTPUT); pinMode(WheelSpeedPin2, INPUT); pinMode(WheelSpeedPin3, INPUT);

attachInterrupt(0, change_int_pin2, CHANGE); attachInterrupt(1, change_int_pin3, CHANGE);

Serial.begin(9600); }

void change_int_pin2() { digitalWrite(led, HIGH);

}

void change_int_pin3() { digitalWrite(led, HIGH); }

Thank you kindly

I tried doing a delay, but the delay didn't seem to be working properly.

Delay will not work inside an interrupt service routine. Do you have to use interrupts? I would have thought polling would be sufficient for this task. Then dealy would work like you think it should.

Just in case it affects how you implement what you want, what is it that causes the wheelspeedpins to go high ?

the wheelspins go high when a sensor goes high in the system. (in this case, I will be simulating the sensor going high manually. This is a controller unit that detects when brakes on a car have been enabled).

I just need to have the LED flash or turn on for a few seconds telling me (the viewer) that the brakes have been applied. for both wheelspins.

Unless the wheels are spinning at incredible speed I would forget about using interrupts. Read the sensors each time through loop() and do the LED on/off/flash timing using millis() as your timer, not delay(), because if the first LED is to stay on for say 5 seconds and you use delay(), then the program cannot read the other sensor during the delay.

Look at the BlinkWithoutDelay example in the IDE to see how millis() can be used like this

You do realize that the way you intialized the interrupts, the signal going low will do the same thing? Since you only care about the signal going high, I would initialize the interrupts with "RISING" instead of "CHANGE". That said, I would probably just have the ISRs (interrupt service routines) change a flag (boolean variable) instead of actually turning a LED on. Then in the loop() while it is doing other things poll the flags and act based on the value of the flaf. I'd probably splice in the methodology of http://arduino.cc/en/Tutorial/BlinkWithoutDelay and when the timing check routines note that it's time to turn the LEDs off I would reset the flag that was changed in the ISR.

Another thought is to have the ISRs both set a flag and capture the current millis() value into a long variable. Then in the void loop have an If statement that check the flag. If the flag is set, check the current millis() to the stored long variable. If the difference is greater than your time out, then turn off the LED and clear the flag, else send a digitalWrite to turn the LED on (after the first check, you may be turning on an already on LED but that doesn't hurt anything). This way, if the ISR is serviced again while the LED is still on, it just resets the timing counter.

Remember, you want to keep our ISRs as short as possible because the uP can't sense any other interrupts while servicing one, and the internal counter incrementing the mills() value pauses. (There may be a 1 or 2 interrupt buffer, but I wouldn't want to rely on that).

Or take UKHeliBob's advice (written while I was writing this post) and skip using ISRs entirely.

Or take UKHeliBob's advice (written while I was writing this post) and skip using ISRs entirely.

I also offered the same advice ( and to look at blink without delay, without delay) in the OP's other post on this subject.