Need help with sketch structure and if/else if function

Hi there,

I've made myself a device similar to an Arduboy: Seeeduino Xiao driving an ssd1306 128*64 display with four switches for direction. I'm very new to coding and Arduino having picked it up last year as a hobby to get out of a Covid-induced funk.
I attach a link to a YouTube video, as I think this will make it easier to explain what I am trying to achieve.

Demonstration

I'm also posting a link to the

Code posted at GitHub

I have some basic problems with game structure and loops.
What I have now: the game starts out with room2doors.h.
pressing a button brings up a different "page".
[please note that the following code was in, and works in, the void loop(); but not in each "page", as in the code on Github]

if (upButtonState == LOW){             
                          twoDoors();                                        
                           
                     } else if (downButtonState == LOW){            
                          sofaWall();                              
                          
                     } else if (leftButtonState == LOW){                   
                          library();
                         
                     } else if (rightButtonState == LOW){
                           fourthWall();
                     }   

pressing the up switch leads to "two doors"
pressing the down switch leads to the "sofa wall"
the left button switch leads to the "library", and
the right button switch leads to the "fourth wall".
This works fine... as far as it does.

However, what I can't go further than that: I can't use the same ""if, else if"" structure in the next "page".

For example, if I press the left button switch, this initiates void library() [which I've placed in library.h ] but when in void library() I'd like further choices: up switch might lead to a book+text; the left switch might lead to an image of a vase; the right switch might lead to a close up of the lounge chair; and the down switch might lead back to "room2doors".

I don't understand why I cannot use the "if, else if" button control structure in the dependent files.
I suspect there is a basic answer to this question.
I also suspect that I'm trying to use a screwdriver as a hammer. I'd really appreciate some help in identifying the right tool to achieve my goal (multiple nested sequential choices).

Thanks in advance.

You could use another set of if/else to select the page and inside THOSE put the code to act on the buttons for that page.

  if (page == 1)
  {
.
.
.
  }
  else if (page == 2)
  {
.
.
.
  }
  else if (page == 3)
  {
.
.
.
  }

Thank you, John,

I will try your suggestion and post back.

Angus

Hi John,

Am I correct in assuming that you are suggesting that I create a class of functions called "page"?
Each of my .h files as a "page" would then be assigned a number? something like:

const int page = 1  //[I'm not sure how the sketch would distinguish the pages from each other? ]  
// 

Assuming the library() in the library.h file was page 6

The if, else if function in the loop() in the .ino file would be:

if (page ==1)
{
page1();  //[presumably I could keep the original function name, but I'll go with page1() for clarity;
}
[...]
// here there would be 4 other else if functions until:

else if (page == 6)
{library();
}

in the library.h file would be something along the lines of:

if (upButtonState == LOW){             
                         book();                                        
                           
                     } else if (downButtonState == LOW){            
                          library();                              
                          
                     } else if (leftButtonState == LOW){                   
                         lounger();
                         
                     } else if (rightButtonState == LOW){
                           dagger();
                     }   

Am I on the right track?
I'm a total noob and I'll confess to finding your first response somewhat cryptic...

Thanks again.

I wouldn't make it a 'const' (constant). That means you can never change it and show other pages. In this case, page 1 is your "room2doors" page. This page has four places you can go with the push of a button: twoDoors, sofaWall, library, and fourthWall. In the room2doors page you wait for a button to go from unpressed to pressed (see the StateChangeDetection example). When a button is pressed, the corresponding image is displayed and the 'page' variable is changed to keep track of the change of page. If you press the button for 'library', for example, the image for 'library' is displayed and you set the 'page' variable to, say, 3 to represent the 'library' page. When page is set to 3 you again wait for a button to go from unpressed to pressed. That button press will select 'book', 'library', 'lounger', or 'dagger'. you put up the image and set 'page' to the number that matches the new page.

What I would do is assign a unique 'page' value for each image. A good way to assign numbers is with an 'enum' (enumeration). It's just a list of names to which values are assigned:

[code]
enum buttons {UpButtonIndex, DownButtonIndex, LeftButtonIndex, RightButtonIndex};
enum pages {room2doors, twoDoors, sofaWall, library, fourthWall, book, lounger, dagger, NUMBER_OF_IMAGES} page;

const int PageLinks[NUMBER_OF_IMAGES][4] = 
{
  {twoDoors, sofaWall, library, fourthWall}, // room2doors
  {0, 0, 0, 0}, // twoDoors
  {0, 0, 0, 0}, // sofaWall
  {book, library, lounger, dagger}, // library
  {0, 0, 0, 0}, // fourthWall
  {0, 0, 0, 0}, // book
  {0, 0, 0, 0}, // lounger
  {0, 0, 0, 0}, // dagger
};


void setup()
{
//...

  page = room2doors;  // Initial page
  displayImage(page);
}

void loop()
{
  static int upButtonPreviousState = HIGH;
  static int downButtonPreviousState = HIGH;
  static int leftButtonPreviousState = HIGH;
  static int rightButtoPreviousnState = HIGH;
  
  int upButtonState = digitalRead(UpButtonPin);
  int downButtonState = digitalRead(DownButtonPin);
  int leftButtonState = digitalRead(LeftButtonPin);
  int rightButtonState = digitalRead(RightButtonPin);

  if (upButtonState != upButtonPreviousState)
  {
    upButtonPreviousState = upButtonState;
    if (upButtonState == LOW)
    {
      // button just pressed
      // Follow the link for the current pagbe and button
      page = PageLinks[page][UpButtonIndex]; 
      displayImage(page);
    }
  }

  // Do similar for the other three buttons
}
[/code]

OK, it's starting to make sense.
I was not aware of the enum function, but I can see from your example how my original structure was locked to just the rooms set out and that enum will provide the flexibility required.

Thank you for taking the time to provide this comprehensive answer, I think I can move forward now.

Angus

OK, I understood and implemented your suggestions, but the code is not compiling.
I will post the code separately on GitHub https://github.com/ANGUSsugna/SEEN/find/main; the error messages are attached below but the short version is this:

First, I'm getting the following error with respect to the "PageLinks":
for example:
'Room2doors' redeclared as different kind of symbol .
I thought the problem might be that the #define room2doors.h had the same name as the room2doors page name, so I changed the names of the PageLinks by varying capitalization to Room2doors. Unfortunately this did not work.
Re-reading the error code I understood that the problem is that the enum function is defining them as pages whereas, in the -LinkPage name-.h files the code starts with void LinkPage name(){
OK, it can't be an "enum" and a "void", I understand that's a conflict. But how to resolve it?
I tried removing "void" but that did not work.
I tried replacing "void" with enum -LinkPage (), but that did not work.
I tried replacing "void" with page -LinkPage () , but that did not work.
I tried replacing "void" with displayImage -LinkPage (), but that did not work.
I tried replacing "void" with display -LinkPage (), but that did not work.
I tried replacing "void" with int -LinkPage (), but that did not work.
I tried replacing "void" with const int -LinkPage (), but that did not work.

So that's the first category of error, and my efforts to resolve it. The two books I've borrowed from the library (Sam's Teach Yourself Arduino Programming, and Arduino Sketches, Tools and Techniques for Programming Wizardry) don't even list enum in the index! So I've run out of permutations to try to resolve this conflict. I understand the basic problem, I just don't see what avenues are left to explore...

The second error is:
too many initializers for 'const int [20][4].
This is error is even more problematic for me because the number of constant integers appears to be correct! There are not too many initializers: there are 20 PageLinks and 4 directional buttons. What's the problem?

Related to this last is one more main category of error:
GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]
Googling this leads to forum discussions regarding C and C++ which are so far above my level of comprehension I haven't done more than skim them.

Once again, I'd appreciate any help.

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Seeeduino XIAO, Arduino, Off"

GFX_SEEN-post-help5:64:13: error: 'Room2doors' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

             ^~~~~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:39:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\room2doors.h:1:11: note: previous declaration 'const int Room2doors()'

 const int Room2doors(){

           ^~~~~~~~~~

GFX_SEEN-post-help5:64:25: error: 'TwoDoors' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                         ^~~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:40:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\twoDoors.h:2:11: note: previous declaration 'const int TwoDoors()'

 const int TwoDoors(){

           ^~~~~~~~

GFX_SEEN-post-help5:64:35: error: 'SofaWall' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                   ^~~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:41:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\sofaWall.h:2:11: note: previous declaration 'const int SofaWall()'

 const int SofaWall(){

           ^~~~~~~~

GFX_SEEN-post-help5:64:45: error: 'Library' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                             ^~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:42:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\library.h:1:11: note: previous declaration 'const int Library()'

 const int Library(){

           ^~~~~~~

GFX_SEEN-post-help5:64:54: error: 'fourthwall' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                      ^~~~~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:43:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\fourthWall.h:2:11: note: previous declaration 'const int fourthwall()'

 const int fourthwall(){

           ^~~~~~~~~~

GFX_SEEN-post-help5:64:66: error: 'book' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                  ^~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:44:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\Book.h:1:11: note: previous declaration 'const int book()'

 const int book(){

           ^~~~

GFX_SEEN-post-help5:64:72: error: 'Lounger' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                        ^~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:45:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\lounger.h:1:11: note: previous declaration 'const int Lounger()'

 const int Lounger(){

           ^~~~~~~

GFX_SEEN-post-help5:64:89: error: 'hall' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                         ^~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:47:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\HALL.h:1:11: note: previous declaration 'const int hall()'

 const int hall(){

           ^~~~

GFX_SEEN-post-help5:64:106: error: 'blankWall' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                          ^~~~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:49:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\BLANKWall.h:1:11: note: previous declaration 'const int blankWall()'

 const int blankWall(){

           ^~~~~~~~~

GFX_SEEN-post-help5:64:117: error: 'Mirror' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                     ^~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:50:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\mirror.h:1:11: note: previous declaration 'const int Mirror()'

 const int Mirror(){

           ^~~~~~

GFX_SEEN-post-help5:64:135: error: 'Eye1' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                                       ^~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:52:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\eye1.h:1:11: note: previous declaration 'const int Eye1()'

 const int Eye1(){

           ^~~~

GFX_SEEN-post-help5:64:141: error: 'Eye2' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                                             ^~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:53:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\eye2.h:1:11: note: previous declaration 'const int Eye2()'

 const int Eye2(){

           ^~~~

GFX_SEEN-post-help5:64:147: error: 'Eye3' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                                                   ^~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:54:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\eye3.h:1:11: note: previous declaration 'const int Eye3()'

 const int Eye3(){

           ^~~~

GFX_SEEN-post-help5:64:153: error: 'booK1' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                                                         ^~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:55:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\book1.h:1:11: note: previous declaration 'const int booK1()'

 const int booK1(){

           ^~~~~

GFX_SEEN-post-help5:64:160: error: 'booK2' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                                                                ^~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:56:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\book2.h:1:11: note: previous declaration 'const int booK2()'

 const int booK2(){

           ^~~~~

GFX_SEEN-post-help5:64:167: error: 'booK3' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                                                                       ^~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:57:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\book3.h:1:11: note: previous declaration 'const int booK3()'

 const int booK3(){

           ^~~~~

GFX_SEEN-post-help5:64:174: error: 'SofaDetail' redeclared as different kind of symbol

 enum pages {Room2doors, TwoDoors, SofaWall, Library, fourthwall, book, Lounger, daGGer, hall, arrowwall, blankWall, Mirror, LipStick, Eye1, Eye2, Eye3, booK1, booK2, booK3, SofaDetail,     NUMBER_OF_IMAGES} page;

                                                                                                                                                                              ^~~~~~~~~~

In file included from C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:58:0:

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\sofaDetail.h:1:11: note: previous declaration 'const int SofaDetail()'

 const int SofaDetail(){

           ^~~~~~~~~~

GFX_SEEN-post-help5:94:1: error: too many initializers for 'const int [20][4]'

 };

 ^

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

GFX_SEEN-post-help5:94:1: error: invalid conversion from 'const int (*)()' to 'int' [-fpermissive]

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino: In function 'void setup()':

GFX_SEEN-post-help5:123:8: error: cannot convert 'const int()' to 'pages' in assignment

 page = Room2doors;  // Initial page

        ^~~~~~~~~~

GFX_SEEN-post-help5:124:1: error: 'displayImage' was not declared in this scope

 displayImage(page);

 ^~~~~~~~~~~~

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino:124:1: note: suggested alternative: 'display'

 displayImage(page);

 ^~~~~~~~~~~~

 display

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help5\GFX_SEEN-post-help5.ino: At global scope:

GFX_SEEN-post-help5:127:1: error: expected declaration before '}' token

 }

 ^

exit status 1

'Room2doors' redeclared as different kind of symbol



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The name of an enum value can't be the same as the name of a function. Change whichever set is easier to change.

Hello
Start the name of an enum value with a capital letter.
That will help.

But if room2doors in enum isn't the same as void room2doors() how will the sketch know to fetch the latter from the room2doors.h file?
It seems really counter-intuitive that they should not have the same name.

Is it safe to assume that Room2doors is sufficient to distinguish from room2doors?

Anyway, thanks again.
I'll try some more permutations tomorrow...

Hi Paul and John, thank you both.

As recommended, changing the enum value name solved the first issue- I still don't understand the manner in which the enum value is linked with the function contained in the .h file. I think once I get the sketch working, the mechanics will become clearer to me. Anyway, the main this is that the error messages have disappeared, so thank you.

I also understand now the "too many initializers" error: there were too many lines for the number of PageLinks, it's expecting them to be the same (20, at present) and I had 26 initializers. So I resolved that issue as well.

I have one final remaining issue, which is:
displayImage [see error code attached] is not declared.

I understand that the line displayImage(page); will call up the relevant "page" .h file corresponding to the selection of the button press in a specific initializer line.
The error code suggest I replace displayImage with display (command from the Adafruit Library), unsurprisingly that didn't work when I tried it.
In the global variables I tried declaring displayImage a number of different ways, but (as is obvious) I'm throwing darts blindly at the wall:
//displayImage(PageLinks);// didn't work
//displayImage(PageLinks, page);// didn't work
//displayImage(const int PageLinks); didn't work
//displayImage(enum buttons, const int PageLinks, enum pages);

Here is the almost working code ( "page .h" files not attached)

#include <SPI.h>
#include <Wire.h> //ANGUS
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include <Fonts/FreeSerif9pt7b.h>

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);//ANGUS

#include "pocKonsoLOGO.h"

///// Switches 

const int upButton = 9;              //setting up buttons for pocKonso
int upButtonState = HIGH;
int lastupButtonState = LOW;

const int downButton = 10;            
int downButtonState = HIGH;
int lastdownButtonState = LOW;

const int leftButton = 7;
int leftButtonState = HIGH;
int lastleftButtonState = LOW;

const int rightButton = 8;
int rightButtonState = HIGH;
int lastrightButtonState = LOW;

unsigned long lastDebounceTime = 0; // didn't end up using this code; can leave it 
unsigned long debounceDelay = 50;   // didn't end up using this code 



/////////////////ROOMS//////////////
#include "room2doors.h"
#include "twodoors.h"
#include "sofawall.h"
#include "library.h"
#include "fourthwall.h"
#include "Book.h"
#include "lounger.h"
#include "dagger.h"
#include "HALL.h"
#include "ARROWWALL.h"
#include "BLANKWall.h"
#include "mirror.h"
#include "lipstick.h"
#include "eye1.h"
#include "eye2.h"
#include "eye3.h"
#include "book1.h"
#include "book2.h"
#include "book3.h"
#include "sofadetail.h"
  
///////////////////// ROOM LINKS ////////////////

enum buttons {upButtonIndex, downButtonIndex, leftButtonIndex, rightButtonIndex};

enum pages {room2doors, twodoors, sofawall, library, fourthwall, Book, lounger, dagger, HALL, ARROWWALL, BLANKWall, mirror, lipstick, eye1, eye2, eye3, book1, book2, book3, sofadetail,     NUMBER_OF_IMAGES} page;

const int PageLinks[NUMBER_OF_IMAGES][4] = 
{
  {twodoors, sofawall, library, fourthwall}, // room2doors
  {HALL, room2doors, ARROWWALL, BLANKWall}, // twodoors
  {mirror, room2doors, lipstick, sofadetail}, // sofawall
  {Book, room2doors, lounger, dagger}, // library
  {eye1, room2doors, eye2, eye3}, // fourthwall
  
  {book1, library, book2, book3}, // Book
  {library, library, library, library}, // lounger
  {library, library, library, library}, // dagger
  {room2doors, room2doors, room2doors, room2doors}, // HALL
  {twodoors, room2doors,sofawall, HALL}, // ARROW WALL
  
  {twodoors, room2doors, HALL, sofawall}, //BLANK Wall
  {sofawall, sofawall, lipstick, dagger}, //mirror
  {sofawall, sofawall, dagger, mirror}, //lipstick 
  {sofawall, sofawall, mirror, lipstick}, //dagger
  {fourthwall, fourthwall, fourthwall, fourthwall}, //eye1
/*                                                        // too many initializers... easy to work around.
  {fourthwall, fourthwall, fourthwall, fourthwall}, //eye2 
  {fourthwall, fourthwall, fourthwall, fourthwall}, //eye3
  {Book, Book, Book, Book}, // book1
  {Book, Book, Book, Book}, // book2
  {Book, Book, Book, Book}, // book3
  {sofawall, sofawall, sofawall, sofawall}, //sofadetail 
  */
  };

//displayImage(PageLinks);// didn't work 
//displayImage(PageLinks, page);// didn't work 
//displayImage(const int PageLinks); didn't work
//displayImage(enum buttons, const int PageLinks, enum pages);

//////////////////////////////////////////

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
 
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }

display.setRotation(2);     // Rotate display 180 for pocKonso

pinMode (upButton, INPUT_PULLUP);
pinMode (downButton, INPUT_PULLUP);
pinMode (leftButton, INPUT_PULLUP);
pinMode (rightButton, INPUT_PULLUP);
   
  display.clearDisplay();
  display.setRotation(2);
  display.drawBitmap(0, 0, gImage_pocKonsoLOGO, 128, 64, 1); //This is the pocKonso splash screen
  display.display();

      delay(2000);
      display.clearDisplay();     // clear the display 

page = room2doors;  // Initial page
displayImage(page);
}

}
void loop() {
  // put your main code here, to run repeatedly:
  static int upButtonPreviousState = HIGH;
  static int downButtonPreviousState = HIGH;
  static int leftButtonPreviousState = HIGH;
  static int rightButtoPreviousnState = HIGH;
  
  int upButtonState = digitalRead(UpButtonPin);
  int downButtonState = digitalRead(DownButtonPin);
  int leftButtonState = digitalRead(LeftButtonPin);
  int rightButtonState = digitalRead(RightButtonPin);
                    

  if (upButtonState != upButtonPreviousState)
  {
    upButtonPreviousState = upButtonState;
    if (upButtonState == LOW)
     {      // button just pressed // Follow the link for the current page and button
      page = PageLinks[page][UpButtonIndex]; 
      displayImage(page);    
     }         
    }
    if (downButtonState != downButtonPreviousState)
  {
    downButtonPreviousState = downButtonState;
    if (downButtonState == LOW)
     {
      // button just pressed
      // Follow the link for the current pagbe and button
      page = PageLinks[page][downButtonIndex]; 
      displayImage(page);    
     }         
    }
if (leftButtonState != leftButtonPreviousState)
  {
    leftButtonPreviousState = leftButtonState;
    if (leftButtonState == LOW)
     {
      // button just pressed
      // Follow the link for the current pagbe and button
      page = PageLinks[page][leftButtonIndex]; 
      displayImage(page);    
     }         
    }
if (rightButtonState != rightButtonPreviousState)
  {
    rightButtonPreviousState = rightButtonState;
    if (rightButtonState == LOW)
     {
      // button just pressed
      // Follow the link for the current pagbe and button
      page = PageLinks[page][UpButtonIndex]; 
      displayImage(page);    
     }         
    }    
}

And here are the straggler error codes:

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Seeeduino XIAO, Arduino, Off"

GFX_SEEN-post-help-Oct17:100:60: error: expected constructor, destructor, or type conversion before ';' token

 displayImage(enum buttons, const int PageLinks, enum pages);

                                                            ^

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help-Oct17\GFX_SEEN-post-help-Oct17.ino: In function 'void setup()':

GFX_SEEN-post-help-Oct17:129:1: error: 'displayImage' was not declared in this scope

 displayImage(page);

 ^~~~~~~~~~~~

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help-Oct17\GFX_SEEN-post-help-Oct17.ino:129:1: note: suggested alternative: 'display'

 displayImage(page);

 ^~~~~~~~~~~~

 display

C:\Users\patte\Documents\Arduino\GFX_SEEN-post-help-Oct17\GFX_SEEN-post-help-Oct17.ino: At global scope:

GFX_SEEN-post-help-Oct17:132:1: error: expected declaration before '}' token

 }

 ^

exit status 1

expected constructor, destructor, or type conversion before ';' token



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

[quote="angussugna, post:11, topic:911217"]

 display.clearDisplay();
  display.setRotation(2);
  display.drawBitmap(0, 0, gImage_pocKonsoLOGO, 128, 64, 1); //This is the pocKonso splash screen
  display.display();

      delay(2000);
      display.clearDisplay();     // clear the display 

page = room2doors;  // Initial page
displayImage(page);
}

}     ............????????

Only until you revisit the code a few weeks later. Why invite confusion- just use a completely different variable name.

Hi John,

I've had a chance to plug away at this. I'm down to two problems.
First, I'm still stuck on the displayImage is not declared problem. As noted in my previous post above, I have tried a number of iterations without success. I would appreciate a(nother) shove in the right direction.

A new issue has popped up (which didn't appear in prior versions of the code):
"invalid conversion from 'int' to 'pages' [-f permissive]". I'm not sure what this issue is and why it's rearing its ugly head now, and not before...

Thanks for any help,

Angus

#include <SPI.h>
#include <Wire.h> //ANGUS
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include <Fonts/FreeSerif9pt7b.h>

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);//ANGUS

#include "pocKonsoLOGO.h"

///// Switches 

const int upButtonPin = 9;              //setting up buttons for pocKonso
int upButtonState = HIGH;
int lastupButtonState = LOW;

const int downButtonPin = 10;            
int downButtonState = HIGH;
int lastdownButtonState = LOW;

const int leftButtonPin = 7;
int leftButtonState = HIGH;
int lastleftButtonState = LOW;

const int rightButtonPin = 8;
int rightButtonState = HIGH;
int lastrightButtonState = LOW;

unsigned long lastDebounceTime = 0; // didn't end up using this code
unsigned long debounceDelay = 50;   // didn't end up using this code

/////////////////ROOMS//////////////
#include "room2doors.h"
#include "twodoors.h"
#include "sofawall.h"
#include "library.h"
#include "fourthwall.h"
#include "Book.h"
#include "lounger.h"
#include "dagger.h"
#include "HALL.h"
#include "ARROWWALL.h"
#include "BLANKWall.h"
#include "mirror.h"
#include "lipstick.h"
#include "eye1.h"
#include "eye2.h"
#include "eye3.h"
#include "book1.h"
#include "book2.h"
#include "book3.h"
#include "sofadetail.h"
  
///////////////////// ROOM LINKS ////////////////

enum buttons {upButtonIndex, downButtonIndex, leftButtonIndex, rightButtonIndex};

enum pages {room2doors, twodoors, sofawall, library, fourthwall, Book, lounger, dagger, HALL, ARROWWALL, BLANKWall, mirror, lipstick, eye1, eye2, eye3, book1, book2, book3, sofadetail,     NUMBER_OF_IMAGES} page;

const int PageLinks[NUMBER_OF_IMAGES][4] = 
{
  {twodoors, sofawall, library, fourthwall}, // room2doors
  {HALL, room2doors, ARROWWALL, BLANKWall}, // twodoors
  {mirror, room2doors, lipstick, sofadetail}, // sofawall
  {Book, room2doors, lounger, dagger}, // library
  {eye1, room2doors, eye2, eye3}, // fourthwall
  
  {book1, library, book2, book3}, // Book
  {library, library, library, library}, // lounger
  {library, library, library, library}, // dagger
  {room2doors, room2doors, room2doors, room2doors}, // HALL
  {twodoors, room2doors,sofawall, HALL}, // ARROW WALL
  
  {twodoors, room2doors, HALL, sofawall}, //BLANK Wall
  {sofawall, sofawall, lipstick, dagger}, //mirror
  {sofawall, sofawall, dagger, mirror}, //lipstick 
  {sofawall, sofawall, mirror, lipstick}, //dagger
  {fourthwall, fourthwall, fourthwall, fourthwall}, //eye1
/*  
  {fourthwall, fourthwall, fourthwall, fourthwall}, //eye2
  {fourthwall, fourthwall, fourthwall, fourthwall}, //eye3
  {Book, Book, Book, Book}, // book1
  {Book, Book, Book, Book}, // book2
  {Book, Book, Book, Book}, // book3
  {sofawall, sofawall, sofawall, sofawall}, //sofadetail 
  */
  };



//////////////////////////////////////////

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
 
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }

display.setRotation(2);     // Rotate display 180 for pocKonso

pinMode (upButtonPin, INPUT_PULLUP);
pinMode (downButtonPin, INPUT_PULLUP);
pinMode (leftButtonPin, INPUT_PULLUP);
pinMode (rightButtonPin, INPUT_PULLUP);
   
  display.clearDisplay();
  display.setRotation(2);
  display.drawBitmap(0, 0, gImage_pocKonsoLOGO, 128, 64, 1); //This is the pocKonso splash screen
  display.display();

      delay(2000);
      display.clearDisplay();     // clear the display 

page = room2doors;  // Initial page
displayImage(page);
}

void loop() {
  // put your main code here, to run repeatedly:
  static int upButtonPreviousState = HIGH;
  static int downButtonPreviousState = HIGH;
  static int leftButtonPreviousState = HIGH;
  static int rightButtonPreviousState = HIGH;
  
  int upButtonState = digitalRead(upButtonPin);
  int downButtonState = digitalRead(downButtonPin);
  int leftButtonState = digitalRead(leftButtonPin);
  int rightButtonState = digitalRead(rightButtonPin);
                    

  if (upButtonState != upButtonPreviousState)
  {
    upButtonPreviousState = upButtonState;
    if (upButtonState == LOW)
     {      // button just pressed // Follow the link for the current page and button
      page = PageLinks[page][upButtonIndex]; 
      displayImage(page);    
     }         
    }
    if (downButtonState != downButtonPreviousState)
  {
    downButtonPreviousState = downButtonState;
    if (downButtonState == LOW)
     {
      // button just pressed
      // Follow the link for the current page and button
      page = PageLinks[page][downButtonIndex]; 
      displayImage(page);    
     }         
    }
   if (leftButtonState != leftButtonPreviousState)
  {
    leftButtonPreviousState = leftButtonState;
    if (leftButtonState == LOW)
     {
      // button just pressed
      // Follow the link for the current page and button
      page = PageLinks[page][leftButtonIndex]; 
      displayImage(page);    
     }         
    }
     if (rightButtonState != rightButtonPreviousState)
  {
    rightButtonPreviousState = rightButtonState;
    if (rightButtonState == LOW)
     {
      // button just pressed
      // Follow the link for the current page and button
      page = PageLinks[page][rightButtonIndex]; 
      displayImage(page);    
     }         
    }  
}

Two flavours, one old and one new, of error codes here:

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Seeeduino XIAO, Arduino, Off"

C:\Users\patte\Documents\Arduino\GFX_SEEN-Almost-There1\GFX_SEEN-Almost-There1.ino: In function 'void setup()':

GFX_SEEN-Almost-There1:124:1: error: 'displayImage' was not declared in this scope

 displayImage(page);

 ^~~~~~~~~~~~

C:\Users\patte\Documents\Arduino\GFX_SEEN-Almost-There1\GFX_SEEN-Almost-There1.ino:124:1: note: suggested alternative: 'display'

 displayImage(page);

 ^~~~~~~~~~~~

 display

C:\Users\patte\Documents\Arduino\GFX_SEEN-Almost-There1\GFX_SEEN-Almost-There1.ino: In function 'void loop()':

GFX_SEEN-Almost-There1:145:43: error: invalid conversion from 'int' to 'pages' [-fpermissive]

       page = PageLinks[page][upButtonIndex];

              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

GFX_SEEN-Almost-There1:146:7: error: 'displayImage' was not declared in this scope

       displayImage(page);

       ^~~~~~~~~~~~

C:\Users\patte\Documents\Arduino\GFX_SEEN-Almost-There1\GFX_SEEN-Almost-There1.ino:146:7: note: suggested alternative: 'display'

       displayImage(page);

       ^~~~~~~~~~~~

       display

GFX_SEEN-Almost-There1:156:45: error: invalid conversion from 'int' to 'pages' [-fpermissive]

       page = PageLinks[page][downButtonIndex];

              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

GFX_SEEN-Almost-There1:157:7: error: 'displayImage' was not declared in this scope

       displayImage(page);

       ^~~~~~~~~~~~

C:\Users\patte\Documents\Arduino\GFX_SEEN-Almost-There1\GFX_SEEN-Almost-There1.ino:157:7: note: suggested alternative: 'display'

       displayImage(page);

       ^~~~~~~~~~~~

       display

GFX_SEEN-Almost-There1:167:45: error: invalid conversion from 'int' to 'pages' [-fpermissive]

       page = PageLinks[page][leftButtonIndex];

              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

GFX_SEEN-Almost-There1:168:7: error: 'displayImage' was not declared in this scope

       displayImage(page);

       ^~~~~~~~~~~~

C:\Users\patte\Documents\Arduino\GFX_SEEN-Almost-There1\GFX_SEEN-Almost-There1.ino:168:7: note: suggested alternative: 'display'

       displayImage(page);

       ^~~~~~~~~~~~

       display

GFX_SEEN-Almost-There1:178:46: error: invalid conversion from 'int' to 'pages' [-fpermissive]

       page = PageLinks[page][rightButtonIndex];

              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

GFX_SEEN-Almost-There1:179:7: error: 'displayImage' was not declared in this scope

       displayImage(page);

       ^~~~~~~~~~~~

C:\Users\patte\Documents\Arduino\GFX_SEEN-Almost-There1\GFX_SEEN-Almost-There1.ino:179:7: note: suggested alternative: 'display'

       displayImage(page);

       ^~~~~~~~~~~~

       display

exit status 1

'displayImage' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

What is in your #include files? I don't have a hope of compiling your sketch without those. Maybe you can attach them as a .zip archive.

I suspect that you displayImage(page) will look something like this:

byte * PageImages[] = {gImage_room2doors, gImage_twodoors, gImage_sofawall, gImage_library,
                       gImage_fourthwall, gImage_Book, gImage_lounger, gImage_dagger,
                       gImage_HALL, gImage_ARROWWALL, gImage_BLANKWall, gImage_mirror,
                       gImage_lipstick, gImage_eye1, gImage_eye2, gImage_eye3,
                       gImage_book1, gImage_book2, gImage_book3, gImage_sofadetail
                      };

void displayImage(pages page)
{
  display.drawBitmap(0, 0, PageImages[page], 128, 64, 1);
}

Hi John, (and anyone else who may wish to chime in)...

Sorry about that. Yes, I should have included the #include files. You assumed that they were all bitmap images. In fact, most of them are graphics made with the commands from the Adafruit GFX library (lines, rectangles, etc...- and a few bitmaps within those graphics).

HOWEVER, thanks to your reply as I was able to understand what was missing and I was able to modify your proposed solution to one I'm pretty sure will work (it's no longer throwing up an error at any rate). Hurray!

I'm left with only the "invalid conversion from 'int' to 'pages' [-f permissive]" error.

GFX_SEEN-Almost-There1:148:43: error: invalid conversion from 'int' to 'pages' [-fpermissive]
       page = PageLinks[page][upButtonIndex];
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

This error is repeated four times, on each line related to each of the four buttons.

The code for the "upButton", for example, is as follows:

 if (upButtonState != upButtonPreviousState)
  {
    upButtonPreviousState = upButtonState;
    if (upButtonState == LOW)
     {      // button just pressed // Follow the link for the current page and button
      page = PageLinks[page][upButtonIndex]; 
      displayImage(page);    
     }         

fairly straightforward: if the upButton is pressed, then the PageLinks array gets looked up and the page related to the listed (pressed) button becomes the page called by displayImage(page).

I think the problem is that room2doors is identified as a "page" in the enum pages function
but then, in the const int PageLinks function is it being identified as a constant integer... hence the error of an "invalid conversion".

Having identified what seems like the most likely culprit of the error, I am unsure how to correct it. Googling this type of error (invalid conversion from 'int') has led me down a rabbithole of stackoverflow.com discussions which do not seem to apply to my situation.

Below is the code which relates to the description. Please don't hesitate to let know

enum buttons {upButtonIndex, downButtonIndex, leftButtonIndex, rightButtonIndex};

enum pages {room2doors, twodoors, sofawall, library, fourthwall, Book, lounger, dagger, HALL, ARROWWALL, BLANKWall, mirror, lipstick, eye1, eye2, eye3, book1, book2, book3, sofadetail,     NUMBER_OF_IMAGES} page;

const int PageLinks[NUMBER_OF_IMAGES][4] = 
{
  {twodoors, sofawall, library, fourthwall}, // room2doors
[remainder of array not shown because unnecessary]

I'm so close, I can almost taste it... but, sadly, another weekend has come to an end without final victory. Once this last hurdle is overcome, the core mechanics will be in place and I can start building in the content :slight_smile:
Good night!

Should change that to:

const pages PageLinks[NUMBER_OF_IMAGES][4] = 
{
1 Like

Oh! So simple!
Looking forward to trying this tonight.

Thank you so much for all your help, John. I really appreciate you taking the time to review my questions and explain the issues and provide direction.

Sincerely,
Angus.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.