Difference between revisions of "Gb.menu"

From Gamebuino Wiki
Jump to: navigation, search
(Changed title depth)
Line 1: Line 1:
 
{{DISPLAYTITLE:gb.menu}}
 
{{DISPLAYTITLE:gb.menu}}
 
__NOTOC__
 
__NOTOC__
= Description =
+
== Description ==
 
Displays a menu to select from a list of items.
 
Displays a menu to select from a list of items.
  
= Syntax =
+
== Syntax ==
 
<pre>gb.menu(menu, MENULENGTH);</pre>
 
<pre>gb.menu(menu, MENULENGTH);</pre>
  
= Parameters =
+
== Parameters ==
 
* menu (char** PROGMEM): the items to select from, stored as a PROGMEM array of strings (see example below).
 
* menu (char** PROGMEM): the items to select from, stored as a PROGMEM array of strings (see example below).
 
* MENULENGTH (byte): the number of items in the menu.
 
* MENULENGTH (byte): the number of items in the menu.
  
= Returns =
+
== Returns ==
 
The number of the item selected, or -1 if menu is left without selecting an item (''char'').
 
The number of the item selected, or -1 if menu is left without selecting an item (''char'').
  
= Example =
+
== Example ==
 
<pre>
 
<pre>
 
#include <SPI.h>
 
#include <SPI.h>
Line 74: Line 74:
 
</pre>
 
</pre>
  
= See also =
+
== See also ==
 
*[http://arduino.cc/en/Reference/String string (Arduino reference)]
 
*[http://arduino.cc/en/Reference/String string (Arduino reference)]
 
*[http://arduino.cc/en/Reference/PROGMEM progmem (Arduino reference)]
 
*[http://arduino.cc/en/Reference/PROGMEM progmem (Arduino reference)]

Revision as of 2014-05-18T09:58:38


Description

Displays a menu to select from a list of items.

Syntax

gb.menu(menu, MENULENGTH);

Parameters

  • menu (char** PROGMEM): the items to select from, stored as a PROGMEM array of strings (see example below).
  • MENULENGTH (byte): the number of items in the menu.

Returns

The number of the item selected, or -1 if menu is left without selecting an item (char).

Example

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

#define MENULENGTH 6
char* PROGMEM menu[MENULENGTH] = {
  "System info",
  "Change game"
};

void setup(){
  gb.begin();
}

void loop(){
  switch(gb.menu(menu, MENULENGTH)){
    case 0:
      displaySystemInfo();
      break;
    case 1:
      gb.changeGame();
      break;
    default:
      break;
  }
}

void displaySystemInfo(){
  while(1){
    if(gb.update()){
      if (gb.buttons.pressed(BTN_C)) {
        gb.sound.playCancel();
        return;
      }
      gb.display.setCursor(0, 0);
      gb.display.print(F("Bat:"));
      gb.display.print(gb.battery.voltage);
      gb.display.println(F("mV"));

      gb.display.print(F("Bat lvl:"));
      gb.display.print(gb.battery.level);
      gb.display.println(F("/4"));

      gb.display.print(F("Light:"));
      gb.display.println(gb.backlight.ambientLight);

      gb.display.print(F("Backlight:"));
      gb.display.println(gb.backlight.backlightValue);

      gb.display.print(F("Volume:"));
      gb.display.print(gb.sound.getVolume());
      gb.display.print(F("/"));
      gb.display.println(gb.sound.volumeMax);
    }
  }
}

See also