It worked fine for other pins such as D3 and D7. So I know from owning an Arduino Zero (same chip) that D4 doesn’t support interrupts. So making a guess I passed digitalPinToInterrupt(4) to attachInterrupt but leave it wired to D2. This should NOT work but it does.
I believe the pin mapping number being returned from the call to digitalPinToInterrupt(2) is incorrect.
Hey… it seems D2 and D4 are switched on the board itself. What? Is this by design? You do realize this will cause a huge amount of headache for people who buy this right?
For example this ONLY works if I wire it to D4
#define LEDD 2
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LEDD as an output.
pinMode(LEDD, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LEDD, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LEDD, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
}
Ok -this was driving me nuts but I think I have the reason why (I don’t have a board in front of me to confirm). It is an issue with how the g_APinDescription[] array is defined with the seeed lotus vs. the arduino zero in their respective variants.cpp files . The third entry (index 2 for pin 2) is PORTA8. If you go to the same variants.cpp file that installs with the arduino zero the third entry is for PORTA14. PORTA8’s is actually conntected to D4.
So if you look at the definition of something like digitalWrite(), it uses the pin number you pass to it as the index for the g_APinDescription[] array. Since PORTA8 is the second index, digital pin 2 is now D4. Seeed - if I’m correct, looks like you have to update your board definitions.
To find the respective variants.cpp files, use the following paths: