I might be popping this into the wrong thread, but since it's related to the library, I'll start here.
My project has two states - manual & automatic. In order to switch between the two, I have a mini pushbutton. Unfortunately, it's cheap, and bounces like a kid on a trampoline -- usually 3-6 times, depending on how I push it.
The mode is "monitored" by a boolean - 1 or 0, and an interrupt changes the value of it.
Unfortunately, when you trigger the interrupt, it runs it's code, then goes right back to where the program was last running. If it's in the middle of the automatic function, it could take up to 30 seconds before the state change is put into effect (LEDs fade between colors, with a delay(30000) between each fade).
As a "fix" I moved the button from an interrupt to the reset pin, and save the state variable into EEPROM. Then, everytime the arduino is powered off or reset, it switches modes. Personally, I think this method is horribly kludgy, if not "inappropriate."
I suppose I could simply break down the delay segments into 10ms increments, and lump them together in a small loop that watches for a change in the state. But that still doesn't fix the bouncing issue.
My "Perfect Case Scenario" would be that if a user pushes the button, the state is switched, and the main loop() would restart, regardless of where the program currently is.
So, to summarize all of this:
- How can I debounce an interrupt? (I'm low on physical space, so proper hardware debouncing (using a schmitt trigger) isn't a great option)
- How can I get the interrupt to literally stop everything and start back at the beginning of the main loop()?
Thanks!