I need an answer fast.I want to make a keyboard class to handle a few buttons attached to my arduino. I want to use interrupts.The problem is I have to use the same interrupt function for all my buttons(it would beimpractical to create a routine for each button).So inside the routine I must know at least what pin fired the interrupt. How can I solve this?(I belive it can be solved by changing some registers but that would be too complicated).PS:there are only two buttons(pins 2 and 3 are enough)
Edit: Isn't possible to create/call an interrupt routine inside a class? (I know that the routine actually doesn't exist initially because the object of the class type wasn't created). Can this be done?
class Keyboard{
private:
struct btn{
boolean pressed;
uint32_t pressTime;
};
btn button1;
public:
void int_handler(){
}
Keyboard(){
attachInterrupt(digitalPinToInterrupt(2),this->int_handler,RISING);
attachInterrupt(digitalPinToInterrupt(3),this->int_handler,RISING);
}
};
Keyboard::int_handler()
must bestatic
.