Hi everyone, im a little stuck with a simple code that i cant figure out how to solve, what i want is:
press a button start doing a function (example blink)
press button again function to stop
press button again start function
.
.
.
what ive read is that i need a change interrupt, still cant figure it out how, the example in the IDE is not what im looking for.
What im trying to do is to store data from an acc. to a micro sd card. so a push botton will start with de data aquisition, then anothe push of the button and stop the daq.
im a bit lost
Delta_G:
You never need an interrupt for a button. Buttons are slow. Interrupts are for really fast and transient things.
False.
If you are alluding to reading a button every so often in a piece of code, it is quite possible that your button press might fall between these hardcoded readings and will not register the button press.
Using a very short interrupt to detect a button press (and possibly debounce the button as well) is the BEST possible practice and this technique is widely used.
Here are some guidelines for interrupts with Arduino:
Where interruptPin is the digital input pin that will cause an interrupt to occur and button is the Interrupt Service Routine (or ISR). This special function will quickly execute whatever you want to do during the interrupt.
Also attach the definition of your ISR in the code like a normal funciton:
void button() {
//whatever you want (keep it simple and quick)
}
Using a very short interrupt to detect a button press (and possibly debounce the button as well) is the BEST possible practice and this technique is widely used.
I think many (including me) would disagree with this for the vast majority of applications.
Switch presses are very long events in the time frame of an embedded microprocessor running code. What you need to do is learn how to write non-blocking code (in a single process environment) or event processing code in a multi thread/process environment.