Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Can I Interrupt on any keypress on this keypad?

I'm learning how to write code interrupt code. I just experimented with my first toy example that I got from here:

const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
 pinMode(ledPin, OUTPUT);
 pinMode(interruptPin, INPUT_PULLUP);
 attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
void loop() {
 digitalWrite(ledPin, state);
}
void blink() {
 state = !state;
}

Now I'm trying to incorporate interrupts into my own project. I have a circuit that looks like this using an Arduino Uno Wifi Rev2, Membrane 3x4 Matrix Keypad, a buzzer, some resistors and an RGB LED:

Can I write code such that it interrupts any time any of the keys is pressed (and I can still tell which key is pressed)? How would I do that?

Answer*

Draft saved
Draft discarded
Cancel
6
  • Why can't I do what Jsotola mentioned in the comment above? Commented May 4, 2020 at 16:42
  • @SaqibAli, even though it is doable, it is more trouble than it is worth ... but it may be a good learning experience Commented May 4, 2020 at 17:40
  • Yes, that might work, but as jsotola says, it's not worth it. Unless you have a specific reason to require an interrupt just use polling. Commented May 4, 2020 at 17:41
  • "Can't" is too strong. You can if you use diodes, as jsoltola says. "You can, if you wire it correctly using diodes, but coding interrupts is tricky and probably not worth the trouble" would be more accurate. Commented Jun 4, 2020 at 1:04
  • 1
    You "can" buy dozens of high powered lasers to heat up a pan to make cookies. It would be cool but terribly expensive and hard to do. But you "can" in the same sense. Actually I think laser cookies is probably a better idea. Commented Oct 1, 2020 at 19:36

AltStyle によって変換されたページ (->オリジナル) /