Hi so i have a scope question...i feel like its a common thing but couldn't find anything on the forums. if it already exists could someone please point me to it.
So the the project im busy with spans across the ino file as well as a couple of header and cpp files. the structure in question is as follows.
i have a class called slider initialized in slider.h:
now all the pieces of code in the UI.cpp file that try to access the instance of slider on the main ino file gives an error:
Compiling 'CameraSlider' for 'Arduino Mega w/ ATmega2560 (Mega 2560)'
UI.cpp:In member function 'void UI::setView(View)'
UI.cpp:9:7: error: 'slider' was not declared in this scope
UI.cpp:In member function 'void UI::splashView()'
UI.cpp:43:2: error: 'slider' was not declared in this scope
Error compiling
#include "UI.h"
void UI::setView(View view)
{
this->currentView = view;
switch (view)
{
case SPLASH:
splashView();
if (slider.isDefaultSequenceSet == true)
sequencePlayerView(slider.defaultSequence);
else
savedSequencesView();
break;
case SEQUENCEPLAYER:
/*sequencePlayerView();*/
break;
case SAVEDSEQUENCES:
savedSequencesView();
break;
case SEQUENCEEDITOR:
sequenceEditorView();
break;
case MOTIONEDITOR:
motionEditorView();
break;
case MANUALCONTROLLER:
manualControlView();
break;
case SETTINGS:
settingsView();
break;
}
}
void UI::splashView()
{
slider.calibrate();
}
void UI::sequencePlayerView(Sequence sequence)
{
}
note that i am using visual micro so the errors may look a bit different to the arduino ide but that also kicks up a fuss.
perhaps alot of figuring out if there is a problem with my code can be avoided if i say that if i initialize a int called test in place of the slider instanciation i also cannot access it in my external UI.cpp file.
i have a class called slider initialized in slider.h:
No, you don't.
now all the pieces of code in the UI.cpp file that try to access the instance of slider on the main ino file gives an error:
How is the compiler supposed to know, when compiling the UI class' files, that some other file contains a definition of that variable?
any idea whats up??
Yes. You are making assumptions that are not valid. Nowhere do you tell the UI class that there is something called slider that it needs to know about.
okay so how would i tell the UI class that there is an instance of slider in the main ino file that i want it to use? sorry for my lacking coding knoledge