I am having an issue with my code. I'm not a programming nor C++ expert by any stretch of imagination so please be patient
My goal is to create a class that can handle an interrupt on an Arduino Nano. By researching this on the internet, I found out, that I would need to create an interrupt handler as a static method of the class.
@b707 How would I do it correctly? I have never before worked with something like this and the code from the interruptHandler is right out of ChatGPT
@sterretje Thank you for your hint! I created a public begin function that is being called in the setup part of the main.cpp. However this didn't resolve the issue.
I added the following to the private members of the class:
static interruptClass *instance;
Then, I added the line
instance = this;
to the constructor in between the braces.
The content of the interruptHandler method is now reduced to:
instance->increment();
However, if I want to compile, I get the following error:
C:\Users\User\AppData\Local\Temp\ccbcijcg.ltrans0.ltrans.o: In function interruptClass::interruptHandler()': <artificial>:(.text+0x21e): undefined reference to interruptClass::instance'
:(.text+0x222): undefined reference to interruptClass::instance' C:\Users\User\AppData\Local\Temp\ccbcijcg.ltrans0.ltrans.o: In function global constructors keyed to 65535_0_interruptClass.cpp.o.1788':
:(.text.startup+0x6e): undefined reference to interruptClass::instance' <artificial>:(.text.startup+0x72): undefined reference to interruptClass::instance'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nanoatmega328\firmware.elf] Error 1