79819591

Date: 2025-11-14 02:24:25
Score: 1.5
Natty:
Report link

I dont know avr specifics much, so hope someone will provide better answer.

Interrupts internally are just table (think array of pointers to functions) that cpu uses to jump to on interrupt, like gpio 1 is index interrupts[GPIOISR+1].

You can register same function for all of them, but then you need to know which one triggered, which would be reading some interrupt mask register, avr specific. Thats more complex and less portable code than declaring functions, and you still need map of registry bit = interrupt number, this doesnt shorten code much, same amount of lines

Its possible to also dynamically generate functions in runtime, but not on avr ( non executable ram), and thats overengineering

You could make macro to define function, to make handler code somewhat easier to modify

DEF_BTN_HDLR(1);  
DEF_BTN_HDLR(2);  

I personally prefer polling for buttons, as polling with some interval around ~50ms automatically does debouncing of switches, there isnt much point for interrupts if you dont have latency requirements. Also, dont arduino has very limited gpio interrupt count? Would you realistically have more than 10 buttons this way?

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: None