I'm new to Arduino and am having some trouble connecting an interrupt switch to any of the following pins:
TX1 18, RX1 19, SDA 20, SCL 21.
I'm trying to connect to these pins because I saw that they were interrupts 2, 3, 4, and 5 respectively.
SCL 21 is the pin I am currently trying to connect to. I have the wiring correct since I tested it with pin 2 (Interrupt 0) and it does what it is supposed to, I just can't get it to work on the SCL 21 pin.
Is 21 the right way to call out the pin? Is 2 in the attachInterrupt command correct since SCL 21 is interrupt port 2? I want to use the pins above since pins 2-13 are already in use. Thank you!
No, it is a Mega. I included that in the title but forgot to iterate it in the post. I have a string of 11 LED's plugged into pins 3-13. They light up from left to right with a red light in the center and the goal is to press a button to stop (interrupt) the sequence on the red light and receive a score. I have two pushbuttons, one to stop the lights and one to cycle through LED sequencing speed. The first pushbutton is wired to pin 2 (Interrupt 0). Since the LED's use the rest of the pins I want to wire the second pushbutton to a different interrupt pin. There is also an LCD (wired to pins 24, 25, 26, 27, 28, and 29) that displays a score based on the first pushbutton and difficulty based on the second button. Since I am out of pins 2, 3 (interrupt 0,1), I am trying to figure out how to wire a second interrupt for the second pushbutton using the pins stated in the original post. I have verified that all of the code works except for what I have posted. I do not know how to call out pin SCL 21 in code and get that pin to function as an interrupt. Any help is greatly appreciated. Thanks!
Unfortunately, using digitalPinToInterrupt has no change. I'm using the following:
const int button1 = 21; //button used in pin 21
void setup() {
attachInterrupt(digitalPinToInterrupt(button1),difficulty,FALLING); //interrupt for button 2
pinMode(button1, INPUT); //sets the pin used by button 1 to input mode
}
void attempt1(){
}
I have tried:
Switching FALLING to RISING
Pins 20, 19, 18
Writing in "21" instead of "button1"
Swapped out all my wires, resistors, and pushbuttons
Resetting the Arduino
are equivalent statements. The benefit of the middle line over the other two is that you can refactor the code for a different interrupt pin simply by changing the value of button1.
So, probably need to do some simpler tests like GolamMostafa suggests. a series of print statements to check if
you enter the interrupt on rising or falling or at all
swapping out the interrupt for anything else, does the code execute?
I think your problem is not in the code you are posting, but the code you aren't sharing.