so i goth this keypad lcd shield with have 5 buttons witch i wut like to make an intterrupt function for becouse my main loop is kinda long and keeps a lot off othere stuff and varibals updated but alle the 5 buttons from the shield lands on analog pin 0 witch aint a intterrupts enabled pin is there any work arounds ??
raschemmel:
There's a really neat thing out now. You should try it . It's called GOOGLE. Boy is it slick. I just type in "Arduino interrupts" and look what I get !" Google
Hey - Look what I get from google -- This forum; with your comment which is absolutely NO HELP AT ALL! What a waste of internet space.. next...
so i goth this keypad lcd shield with have 5 buttons witch i wut like to make an intterrupt function for becouse my main loop is kinda long and keeps a lot off othere stuff and varibals updated but alle the 5 buttons from the shield lands on analog pin 0 witch aint a intterrupts enabled pin is there any work arounds ??
In case you want to combine blocking and slow code in your loop function ewith fast buton readings, use a timer interrupt! Set a timer interrupt frequency of about 500Hz, then evaluate the button state changes 500 times per second within your timer interrupt handling function!
I think you could get away with 50 times/per second Interupt Timer. If you look at the code for the LCD shield you may see how they are handling
it. Look at the Linksprite LCD code.
If you're using the Arduino UNO with the 16x2 LCD Keypad Shield; you can use Pin Change Interrupts on pin A0.
However; Only Left, Up, Right, Down pull the line low enough to trigger the interrupt ( misses Select ).
To overcome this; I soldered a 4.3K-ohm resistor from A0 to GND on top of the shield and used the below values. Now every button causes a Pin Change Interrupt.
enum Buttons { UP, DOWN, RIGHT, LEFT, SELECT, NONE }; // Button Options
Buttons Current_Button = NONE;
void ButtonCheck(int adc_value) {
// The ISR will trigger when button is pressed and when it is let-go
// Keypad WITH 4.3K-ohm Resistor A0 to GND
if (adc_value >= 523) { Current_Button = NONE; return; }
if (adc_value < 46) { Current_Button = RIGHT; }
else if (adc_value < 155) { Current_Button = UP; }
else if (adc_value < 269) { Current_Button = DOWN; }
else if (adc_value < 381) { Current_Button = LEFT; }
else if (adc_value < 523) { Current_Button = SELECT; }
}
void setup() {
cli(); // disable interrupt
// Setup Pin Change Interrupt for Buttons
PCICR =0x02; // Enable 'PCIE1' bit of PCICR Pin Change Interrupt the PCINT1 interrupt
PCMSK1 = 0b00000001; // Pin Change Interrupt Mask ( NA, RESET, A5, A4, A3, A2, A1, A0 ) - Activate A0
sei(); //allows interrupts
}
ISR(PCINT1_vect) {
ButtonCheck(analogRead(0));
}