0
0
Arduinoprogramming~10 mins

attachInterrupt() function in Arduino - Interactive Code Practice

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(2), [1], RISING);
Drag options to blanks, or click blank then click option'
Ainterrupt
BhandleInterrupt
CinterruptHandler
Dhandle
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that is not defined.
Passing the function call with parentheses instead of just the name.
2fill in blank
medium

Complete the code to attach an interrupt on pin 3 that triggers on a falling edge and calls the function interruptRoutine.

Arduino
attachInterrupt(digitalPinToInterrupt(3), interruptRoutine, [1]);
Drag options to blanks, or click blank then click option'
AFALLING
BCHANGE
CLOW
DRISING
Attempts:
3 left
💡 Hint
Common Mistakes
Using RISING instead of FALLING.
Using LOW which is not a valid mode for attachInterrupt().
3fill in blank
hard

Fix the error in the code to correctly attach an interrupt to pin 4 calling the function onInterrupt when the pin changes state.

Arduino
attachInterrupt([1], onInterrupt, CHANGE);
Drag options to blanks, or click blank then click option'
AdigitalPinToInterrupt(4)
B4
Cpin4
Dinterrupt4
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the pin number directly instead of using digitalPinToInterrupt.
Using invalid identifiers like 'pin4' or 'interrupt4'.
4fill in blank
hard

Fill both blanks to attach an interrupt on pin 5 that calls the function myISR when the signal goes LOW.

Arduino
attachInterrupt([1], [2], LOW);
Drag options to blanks, or click blank then click option'
AdigitalPinToInterrupt(5)
BmyISR
CinterruptHandler
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using the pin number directly instead of digitalPinToInterrupt.
Using a wrong function name.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping pins to their interrupt modes for pins 6, 7, and 8.

Arduino
interruptModes = {6: [1], 7: [2], 8: [3]
Drag options to blanks, or click blank then click option'
ARISING
BFALLING
CCHANGE
DLOW
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid modes or repeating the same mode for all pins.
Using lowercase instead of uppercase for modes.