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]