Hello,
I've got a programming question -
can one and the same analog pin on the Atmega1284P be used both for a pin change interrupt and an analogRead?
I've read conflicting info on the web about that.
As part of my CarDuino project, I want to be able to navigate between different menu screens of my display, using three buttons which will act as "forward", "back" and "set" buttons.
To achieve this, I have made a triple voltage divider. Meaning, one pull down resistor on the analog A4 pin on the 1284 goes to ground, and each of the three buttons is connected to a different value resistor, so that when you press either of the buttons, it produces a different analog reading on the pin.
The way I have chosen my resistors, they result in values on the A4 pin from some 4 volts to around 2.9 volts.
If I put in different resistors so that all of them are above 3.3 volts, could I then also do a pin change interrupt on the same A4 pin?
The idea would be to use that interrupt to increase or decrease a number between 1 and about 10, and have that number indicate which menu page is to be shown.
Pseudo (!!) code:
ISR(Pin A4) {
analogValue = analogRead(A4);
if(analogValue is button "back") menuScreen -=1;
if(analogValue is button "forward") menuScreen +=1;
if'(analogValue is button "set") enter set mode;
}
I know that that's a bunch to put inside an interrupt service routine... any suggestions how that ISR could be slimmed down to run a bit faster?
Anyway, in the loop() code, I would then call a function which would create the desired menu page on the screen based on the value of menuScreen.
So, long story short, can I use the same pin both as an analog and a pin change input in the same code?