Hi guys. I am new to arduino and today I set up visual studio code to work with my arduino (uno). I am now trying to create a class but I am running on to some problems with the includes.
class MyButton {
private:
int pin;
int state;
int previousState;
public:
MyButton(int pin);
void poll();
bool isPressedDown();
bool isReleased();
};
In MyButton.cpp, it does not seem to recognize the include, as all variables declared in MyButton.h are red underlined indicating an error. The error is class "Button" has no member "pin" and it is the same for all other variables.
Does anybody have an idea on what the problem could be?
Note: I am not new to programming but I am completely new to c++
Thanks for the feedback. I really appreciate it! I guess I have a lot to learn about C++. Though I am still encountering the same problem. Do you have any idea what could cause this?
And when I try to upload the code to my arduino I get this error:
MyButton.cpp:4:7: error: redefinition of 'class MyButton'
class MyButton
^~~~~~~~
In file included from /Users/lucdrenth/Desktop/Dev/Arduino/buttons/buttons.ino:1:0:
MyButton.cpp:4:7: error: redefinition of 'class MyButton'
class MyButton
^~~~~~~~
In file included from /Users/lucdrenth/Desktop/Dev/Arduino/buttons/MyButton.cpp:1:0:
/Users/lucdrenth/Desktop/Dev/Arduino/buttons/MyButton.h:1:7: note: previous definition of 'class MyButton'
class MyButton {
^~~~~~~~
In file included from /Users/lucdrenth/Desktop/Dev/Arduino/buttons/MyButton.cpp:1:0,
from /Users/lucdrenth/Desktop/Dev/Arduino/buttons/buttons.ino:1:
/Users/lucdrenth/Desktop/Dev/Arduino/buttons/MyButton.h:1:7: note: previous definition of 'class MyButton'
class MyButton {
^~~~~~~~
exit status 1
IntelliSense configuration already up to date. To manually rebuild your IntelliSense configuration run "Cmd+Alt+I"
[Error] Uploading sketch 'buttons.ino': Exit with code=1