Scope of variables in C++
Solution 1:
There's many ways to approach this. One easy way is to pass the needed varaible as an argument into the functions that need it.
// Pass the values needed as arguments
void splash(byte oled, unsigned char* start_logo)
{
oled.startScreen();
oled.clear();
oled.drawImage(start_logo, 0, 0, 128, 8);
}
Another way is to keep the functions as is and declare the variables in the new cpp file
// extern says that this variable is not defined .cpp file
// It's defined in another file
extern SSD1306_Mini oled;
// static in this context makes this variable only visible to this .cpp file
// extern in another file can't get this
static const unsigned char start_logo[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // more
};
void splash()
{
oled.startScreen();
oled.clear();
oled.drawImage(start_logo, 0, 0, 128, 8);
}
void prepareDisplay(){
unsigned int i,k;
unsigned char ch[5];
oled.clear();
oled.startScreen();
oled.cursorTo(0,0);
oled.printString( "ATTiny");
}