description |
---|
This is a basic example, it will show you how to use lists in the LcdMenu library. |
Requested, inspired and based on previous work by @thijstriemstra 馃檹
The supported datatype for the list is String
. This can be used for other primitive datatypes, you just need to pass it as a string and then parse the result to the desired datatype.
// other includes ...
#include <ItemList.h>
#include <LcdMenu.h> // Always comes after every item type import
extern String colors[];
String colors[] = {"Red", "Green", "Blue", "Orange",
"Aqua", "Yellow", "Purple", "Pink"};
ITEM_STRING_LIST("Col", colors, 9, colorsCallback),
{% hint style="danger" %} You must add the size of the array in order for the menu to know when to stop or loop while cycling through the items in the list. {% endhint %}
Constructor reference:
ItemList(const char key, String* items, const uint8_t itemCount, fptrInt callback)
- key: The key of the menu item.
- items: The array of items to display.
- itemCount: The number of items in the array.
- callback: A pointer to the callback function to execute when this menu item is selected.
menu.enter()
Use menu.left()
and/or menu.right()
to cycle through the items
- When
left()
is invoked the view cycles down the list - When
right()
is invoked the view cycles up the list, you can use onlyright()
if you have a single button, because once the menu reaches the end of the list, it automatically goes to the beginning.
When back()
is invoked, the command (callback) bound to the item is invoked.
void colorsCallback(uint16_t pos) {
// do something with the index
Serial.println(colors[pos]);
}
Full example 馃憠 .../examples/List/List.ino