Hi
I want to use an external interrupt with a single push of a push-button.
My question is, can that push button be used again within the interrupt routine to perform some other job?
Something like this:
const byte setButton = 2; // Push Button to activate INTERRUPT
.
.
void setup()
{
.
.
pinMode(setButton, INPUT);
.
attachInterrupt(digitalPinToInterrupt(setButton), setPipe, HIGH);
}
void loop()
{
.
.
.
// ######### MAIN JOB ##########
.
.
}
void setPipe() // ########### For installing/changing pipe
{
.
.
while (digitalRead(setButton) = LOW);
.
.
}
}
Can be done but is not advisable. At the moment that the ISR is executed all other interrupts are disabled; e.g. millis() will stop.
Interrupt service routines need to be short (timewise).
Please tell us why you think that you need an interrupt for a button.
Hi,
Generally speaking no.
What do you intend to do?
Regards.
I want to manually control a stepper to enable me make some physical (non-electronics) changes in my project.
With the push of button, the stepper will open a valve.
Then I can make some physical adjustments.
Pushing the button again, the stepper will close the valve and then continue its normal operation.
Look at the statechange detection example. No need for an interrupt.
sterretje:
Look at the statechange detection example. No need for an interrupt.
Yes, in current scenario the interrupt will not be required.
As others have suggested, have a look at state machines. With one button you can do anything. Utilizing time-based pulses, which is often employed, you can cycle through your states with button pushes that are say at least one second apart. When you arrive at the state where you wish an event to occur, use the equivalent of a 'double click' with two successive button pushes with a significantly reduced timing gap, maybe 200ms. All that is required in your code is some timing tests between each pulse. While this could be polled, as it relies on some timing it may be better to have it interrupt driven depending on how busy the processor is elsewhere and how long/short your gaps are.
DKWatson:
When you arrive at the state where you wish an event to occur, use the equivalent of a 'double click' with two successive button pushes with a significantly reduced timing gap, maybe 200ms. All that is required in your code is some timing tests between each pulse.
Thanks for the great tip!