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?✗ Incorrect
The ISR (Interrupt Service Routine) function is the code that runs when the interrupt happens.
What does the
RISING mode mean in attachInterrupt()?✗ Incorrect
RISING triggers the interrupt when the pin goes from LOW to HIGH.Why should interrupt service routines be kept short?
✗ Incorrect
Long interrupt routines can delay the main program and cause missed events.
Which function stops an interrupt set by
attachInterrupt()?✗ Incorrect
detachInterrupt() disables the interrupt watching the pin.What happens if you use
CHANGE mode in attachInterrupt()?✗ Incorrect
CHANGE mode triggers the interrupt on any change in the pin's state.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.