Hello,
how can I exit a loop when I press the button ( 2 or 8 ) on the keypad. Is possible to using functions attachInterrupt()?
I have ArduinoMega 2560.
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte rowPins[ROWS] = {45, 43, 41, 39};
byte colPins[COLS] = {37, 35, 33, 31};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
volatile int counter =0;
void setup() {
Serial.begin(9600);
attachInterrupt(_, pushButton, HIGH); //interrupt must working when I press key 2 or 8
}
void loop() {
counter++;
Serial.print("counter= ");
Serial.println(counter);
delay(1000);
}
void pushButton(){
counter=0;
}
To get interrupts on Pin 45 ('2') and Pin 41 ('8') you need to set up Pin Change Interrupts. You won't be able to use the other keypad keys while the interrupts are enabled.
Quote tag is not good for code posting. Use code tag. Left most formatting icon </>
I believe you have missed something here, and other places.
void showAnimalBox(){
int startString = encoder+48;
int stopString = encoder+49;
int i = 0;
while (animalBox != startString) {i++;}
while (animalBox != stopString){
i++;
if(animalBox != stopString) {
lcd.print(animalBox);
}
}
}
@jantomsic Look here for keypad tutorial. When you properly can read the buttons you can start to build the menu system.
added:
jantomsic:
No I didn't,...
I just want scrolling in this menus with buttons not with rotating rotary encoder.
If I get this right... You have found some code there they use a rotary encoder to navigate the menu system.
Instead of modifying the code to use buttons to navigate, you thought it would be easier to use the buttons to emulate the behaviour of a rotary encoder..? 
jantomsic:
Yes i can, but this is not what i want. In my project i will have matrix keypad 1x5 with up down left right and select and more then 3 menus and 3 submenus...
Now i just trying and learning, how i will do it...
Please post a link to that keypad. I can visualise 3 different ones; one that needs to be hooked up to an analog pin, one that uses rows and columns and one that just requires 5 inputs on the arduino.
Unfortunately only lot of 10, but it looks good for your project.