0
0
Arduinoprogramming~10 mins

Why interrupts improve responsiveness in Arduino - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to attach an interrupt to pin 2 that calls the function handleInterrupt.

Arduino
attachInterrupt(digitalPinToInterrupt([1]), handleInterrupt, RISING);
Drag options to blanks, or click blank then click option'
A2
B3
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a pin that does not support interrupts.
2fill in blank
medium

Complete the code to declare the interrupt service routine function named handleInterrupt.

Arduino
void [1]() {
  // code to run when interrupt occurs
}
Drag options to blanks, or click blank then click option'
AinterruptHandler
BhandleInterrupt
ConInterrupt
DinterruptRoutine
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than in attachInterrupt.
3fill in blank
hard

Fix the error in the code to correctly enable interrupts.

Arduino
noInterrupts();
// critical code here
[1]();
Drag options to blanks, or click blank then click option'
AdisableInterrupts
BstartInterrupts
CenableInterrupts
Dinterrupts
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function name to enable interrupts.
4fill in blank
hard

Fill both blanks to create a dictionary that maps pin numbers to their interrupt numbers.

Arduino
const int interruptMap[] = { [1]: 0, [2]: 1 };
Drag options to blanks, or click blank then click option'
A2
B3
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using pins that do not correspond to interrupt numbers.
5fill in blank
hard

Fill all three blanks to complete the code that sets up an interrupt and handles it.

Arduino
volatile bool flag = false;

void [1]() {
  flag = true;
}

void setup() {
  attachInterrupt(digitalPinToInterrupt([2]), [3], FALLING);
}

void loop() {
  if (flag) {
    flag = false;
    // handle event
  }
}
Drag options to blanks, or click blank then click option'
AhandleInterrupt
B2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function names or wrong pin number.