Record number of button presses in ISR

Hi All,

I am in process of designing a project as a DC voltage monitor, which turns on and off a relay depending on the voltage. Of course, I am trying to make the project as cost effective as possible.

I have hard coded upper and lower thresholds voltages scaled out of 1023. I need to be able to tweak these values and I am trying to implement these via an interrupt on a button.

The hardware consists of three buttons: CONFIG (interrupt), SET and SELECT buttons. While running the main loop, if the CONFIG button is pressed it raises an interrupt. The program jumps to the ISR.

The initial stage of the ISR to set the deviation from the lower threshold by counting the number of button presses detected on the SET button. To exit this section and proceed to the next section (setting the upper threshold), the SELECT button is pressed. The lower threshold deviation value is then stored in the internal EEPROM.

The program then expects input on the SET button in order to determine the upper threshold value. After the SET button is pressed a number of times, the SELECT button is pressed. The deviation value is then stored in the EEPROM at another address.

Upon resetting the Arduino, the system takes the hard coded values and adds them to the corresponding values in the EEPROM, then moves on to the main loop.

I'll have some LED's to indicate where I am in the procedure and I will implement hw debounce.

I need help in determining which buttons (SET and SELECT) is pressed and how many times the SET button is pressed.

I know it is long and any suggestions would be appreciated.

It is very unlikely that you would need to use interrupts to detect button presses by a human finger. Humans are not that fast.

Just poll the button in every iteration of loop()

Write a short program that just detects the button presses the way you want. When that is reliable you can incorporate it into your main program. At that stage you should just have a number to save in your EEPROM.

If you want any more advice you must post your code - and use code tags (the button that looks like a scroll with <> on it) so it looks like this.

...R

Oh dear! :astonished:

A "newbie" with interrupts again!