The OUT is then connected to an arduino ADC (or just an 328 on a breadboard) AND to an op-amp, LM358, input.
The op-amp is wired as a comparator, and goes low when any of the buttons is pressed. That signal goes to an external interrupt pin.
I made a simple test sketch, that just prints analogRead(ADC_pin) and digitalRead(OP-AMP_pin) to the serial monitor.
That works perfectly: when i press a button, the analog value goes from 1023 to a unique value for each button, and the op-amp signal goes low at the same time. The button value could be like 571 or 572 for one button, but it didn't throw more than that.
Now when i tested the interrupt functionality, which is the whole point of this setup, i did attachInterrupt(OP-AMP_pin, ISR, FALLING) and in the function i read the adc value and print it to serial monitor.
It threw a lot, a button value could throw by +-100.
Next i tried this: i read the adc value 50 times (1ms delay) in the interrupt function, stored that to an volatile array and printed that to the serial monitor in loop(). (The interrupt function wrote a boolean, printValues, 1 and if it was 1 in the loop it printed the array and restored printValues to zero).
and in the function i read the adc value and print it to serial monitor.
Where is your code? Printing to the serial port requires interrupts to be enabled. They are not when your ISR is active. Do NOT use Serial.print() in an ISR.
Now when i tested the interrupt functionality, which is the whole point of this setup, i did attachInterrupt(OP-AMP_pin, ISR, FALLING) and in the function i read the adc value and print it to serial monitor.
Why? Why do you need drop everything and respond to a switch press immediately? On a human scale, polling is good enough.
If your code isn't polling often enough, re-write it so that it is.
kinda unfriendy i think but i try not to get too provoked.
Do NOT use Serial.print() in an ISR.
i moved the Serial.print() to loop:
Next i tried this: i read the adc value 50 times (1ms delay) in the interrupt function, stored that to an volatile array and printed that to the serial monitor in loop(). (The interrupt function wrote a boolean, printValues, 1 and if it was 1 in the loop it printed the array and restored printValues to zero).
but it was still the same.
I would much want to use interrupts because this is a timer/stopwatch-related project.
I would much want to use interrupts because this is a timer/stopwatch-related project.
With a human starting and stopping the timer? Interrupts are not necessary. If the input came from an encoder clicking along at 10000 pulses per second, counting them by polling would not be fast enough.
kinda unfriendy i think but i try not to get too provoked.
There is a sticky at the top of the forum that you are supposed to read before you post here. It tells you that you need to post all of your code. Either you couldn't be bothered to read that, or you thought it didn't apply to you. Kind of unfriendly on your part, I think, but I try not to get too provoked. Don't push me, though.