0
0
Arduinoprogramming~5 mins

attachInterrupt() function in Arduino - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the attachInterrupt() function in Arduino?
The attachInterrupt() function is used to set up an interrupt on a specific pin. It tells the Arduino to watch for a change on that pin and run a special function (called an interrupt service routine) when that change happens.
Click to reveal answer
beginner
What are the three main parameters of attachInterrupt()?
The three main parameters are:<br>1. interrupt number: which interrupt to use (often linked to a pin)<br>2. ISR function: the function to run when the interrupt happens<br>3. mode: the condition that triggers the interrupt (like RISING, FALLING, CHANGE, or LOW)
Click to reveal answer
beginner
What does the mode parameter in attachInterrupt() control?
The mode parameter controls when the interrupt triggers. It can be:<br>- RISING: when the pin goes from LOW to HIGH<br>- FALLING: when the pin goes from HIGH to LOW<br>- CHANGE: when the pin changes in any way<br>- LOW: when the pin is LOW (only on some boards)
Click to reveal answer
intermediate
Why should the function called by attachInterrupt() be short and fast?
Because interrupt functions stop the main program to run immediately, they should be quick to avoid delaying the rest of the program. Long or slow code in interrupts can cause missed events or unstable behavior.
Click to reveal answer
beginner
How do you detach an interrupt that was set with attachInterrupt()?
You use the detachInterrupt() function with the interrupt number to stop the Arduino from watching that interrupt pin.
Click to reveal answer
Which parameter of attachInterrupt() specifies the function to run when the interrupt triggers?
AInterrupt number
BPin number
CMode
DISR function
What does the RISING mode mean in attachInterrupt()?
APin stays LOW
BPin changes from HIGH to LOW
CPin changes from LOW to HIGH
DPin changes in any way
Why should interrupt service routines be kept short?
ATo avoid blocking the main program for too long
BTo make the code easier to read
CTo save memory
DTo use more CPU power
Which function stops an interrupt set by attachInterrupt()?
AstopInterrupt()
BdetachInterrupt()
CremoveInterrupt()
DdisableInterrupt()
What happens if you use CHANGE mode in attachInterrupt()?
AInterrupt triggers on any change from HIGH to LOW or LOW to HIGH
BInterrupt triggers only on LOW state
CInterrupt triggers only on RISING edge
DInterrupt triggers only on FALLING edge
Explain how to use attachInterrupt() to run a function when a button is pressed.
Think about what happens electrically when the button is pressed.
You got /4 concepts.
    Describe why interrupt service routines should be short and what problems can happen if they are not.
    Imagine stopping your friend while they are talking for a quick question versus a long story.
    You got /4 concepts.