diff --git a/README.md b/README.md index e3aaaf48..cfe04bca 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Follow this guide to install the library https://www.arduino.cc/en/guide/librari ### Basic Navigation -See [Basic-Navigation](https://github.com/forntoh/LcdMenu/wiki/Basic-Navigation) +See [Wiki - Basic-Navigation](https://github.com/forntoh/LcdMenu/wiki/Basic-Navigation) ### Submenus -See [Basic-Navigation](https://github.com/forntoh/LcdMenu/wiki/Submenus) \ No newline at end of file +See [Wiki - Submenus](https://github.com/forntoh/LcdMenu/wiki/Submenus) \ No newline at end of file diff --git a/examples/Basic/Basic.ino b/examples/Basic/Basic.ino index 45e8e25f..83eb528f 100644 --- a/examples/Basic/Basic.ino +++ b/examples/Basic/Basic.ino @@ -1,21 +1,49 @@ +/* + Basic Menu Navigation + + This sketch demostrates how to get started with the LcdMenu library + + Circuit: + * Arduino Board + * Keypad pin 1 to digital pin 9 + * Keypad pin 2 to digital pin 8 + * Keypad pin 3 to digital pin 7 + * Keypad pin 4 to digital pin 6 + * Keypad pin 5 to digital pin 5 + * Keypad pin 6 to digital pin 4 + * Keypad pin 7 to digital pin 3 + * Keypad pin 8 to digital pin 2 + * LCD SLC pin to arduino SLC pin + * LCD SDA pin to arduino SDA pin + + created 22 July 2020 + by Forntoh Thomas + + This example is in the public domain. + + https://github.com/forntoh/LcdMenu/tree/master/examples/Basic/Basic.ino + +*/ + #include #include #define LCD_ROWS 2 #define LCD_COLS 16 -void toggleBacklight(); - +// Configure keypad keys char keys[4][4] = {{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}}; - +// Configure keypad pins byte colPins[4] = {5, 4, 3, 2}; byte rowPins[4] = {9, 8, 7, 6}; +// Define the main menu extern MenuItem mainMenu[]; +// Initialize the main menu items MenuItem mainMenu[] = {ItemHeader(), MenuItem("Start service"), MenuItem("Connect to WiFi"), @@ -23,12 +51,16 @@ MenuItem mainMenu[] = {ItemHeader(), MenuItem("Blink SOS"), MenuItem("Blink random"), ItemFooter()}; - +// Construct the LcdMenu LcdMenu menu(LCD_ROWS, LCD_COLS); +// Setup keypad Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4); -void setup() { menu.setupLcdWithMenu(0x27, mainMenu); } +void setup() { + // Initialize LcdMenu with the menu items + menu.setupLcdWithMenu(0x27, mainMenu); +} void loop() { char key = keypad.getKey(); diff --git a/examples/Callbacks/Callbacks.ino b/examples/Callbacks/Callbacks.ino new file mode 100644 index 00000000..05b4dbc8 --- /dev/null +++ b/examples/Callbacks/Callbacks.ino @@ -0,0 +1,99 @@ +/* + Menu Item Callbacks + + This sketch demostrates how to use callback functions in the LcdMenu library + + Circuit: + * Arduino Board + * Keypad pin 1 to digital pin 9 + * Keypad pin 2 to digital pin 8 + * Keypad pin 3 to digital pin 7 + * Keypad pin 4 to digital pin 6 + * Keypad pin 5 to digital pin 5 + * Keypad pin 6 to digital pin 4 + * Keypad pin 7 to digital pin 3 + * Keypad pin 8 to digital pin 2 + * LCD SLC pin to arduino SLC pin + * LCD SDA pin to arduino SDA pin + + created 23 July 2020 + by Forntoh Thomas + + This example is in the public domain. + + https://github.com/forntoh/LcdMenu/tree/master/examples/Callbacks/Callbacks.ino + +*/ + +#include +#include + +#define LCD_ROWS 2 +#define LCD_COLS 16 + +// Declare the call back function +void toggleBacklight(); + +// Configure keypad keys +char keys[4][4] = {{'1', '2', '3', 'A'}, + {'4', '5', '6', 'B'}, + {'7', '8', '9', 'C'}, + {'*', '0', '#', 'D'}}; + +// Configure keypad pins +byte colPins[4] = {5, 4, 3, 2}; +byte rowPins[4] = {9, 8, 7, 6}; + +extern MenuItem mainMenu[]; +extern MenuItem settingsMenu[]; + +MenuItem mainMenu[] = {ItemHeader(), + MenuItem("Start service"), + MenuItem("Connect to WiFi"), + ItemSubMenu("Settings", settingsMenu), + MenuItem("Blink SOS"), + MenuItem("Blink random"), + ItemFooter()}; +/** + * Create submenu and precise its parent + */ +MenuItem settingsMenu[] = {ItemSubHeader(mainMenu), + // + // Include callback in ItemToggle + // + ItemToggle("Backlight", toggleBacklight), + MenuItem("Contrast"), + ItemFooter()}; + +LcdMenu menu(LCD_ROWS, LCD_COLS); + +Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4); + +void setup() { menu.setupLcdWithMenu(0x27, mainMenu); } + +void loop() { + char key = keypad.getKey(); + if (key == NO_KEY) return; + + switch (key) { + case 'A': + menu.up(); + break; + case 'B': + menu.down(); + break; + case 'C': + // callback funtion will be executed when enter is pressed + menu.enter(); + break; + case 'D': + menu.back(); + break; + default: + break; + } +} +/** + * Define callback + */ +void toggleBacklight() { menu.lcd->setBacklight(settingsMenu[1].isOn); } \ No newline at end of file diff --git a/examples/DynamicMenu/DynamicMenu.ino b/examples/DynamicMenu/DynamicMenu.ino new file mode 100644 index 00000000..3cdb9727 --- /dev/null +++ b/examples/DynamicMenu/DynamicMenu.ino @@ -0,0 +1,104 @@ +/* + Dynamic Menu + + This sketch demostrates how to dynamically create sub menu's during runtime + using the LcdMenu library. + + Circuit: + * Arduino Board + * Keypad pin 1 to digital pin 9 + * Keypad pin 2 to digital pin 8 + * Keypad pin 3 to digital pin 7 + * Keypad pin 4 to digital pin 6 + * Keypad pin 5 to digital pin 5 + * Keypad pin 6 to digital pin 4 + * Keypad pin 7 to digital pin 3 + * Keypad pin 8 to digital pin 2 + * LCD SLC pin to arduino SLC pin + * LCD SDA pin to arduino SDA pin + + created 23 July 2020 + by Forntoh Thomas + + This example is in the public domain. + + https://github.com/forntoh/LcdMenu/tree/master/examples/DynamicMenu/DynamicMenu.ino + +*/ + +#include +#include + +#define LCD_ROWS 2 +#define LCD_COLS 16 + +// Configure keypad keys +char keys[4][4] = {{'1', '2', '3', 'A'}, + {'4', '5', '6', 'B'}, + {'7', '8', '9', 'C'}, + {'*', '0', '#', 'D'}}; + +// Configure keypad pins +byte colPins[4] = {5, 4, 3, 2}; +byte rowPins[4] = {9, 8, 7, 6}; + +extern MenuItem mainMenu[]; + +MenuItem mainMenu[] = {ItemHeader ( ), + MenuItem ("Start service " ), + ItemSubMenu("Connect to WiFi", NULL), + MenuItem ("Settings " ), + ItemFooter ( )}; + +char* names[] = {"TP-LINK_AP_F558", "iH2K-7539", "KTA-CONNECT", "SM-G955U241"}; + +LcdMenu menu(LCD_ROWS, LCD_COLS); + +Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4); + +void setup() { menu.setupLcdWithMenu(0x27, mainMenu); } + +void loop() { + char key = keypad.getKey(); + if (key == NO_KEY) return; + + switch (key) { + case 'A': + menu.up(); + break; + case 'B': + menu.down(); + break; + case 'C': + menu.enter(); + break; + case 'D': + menu.back(); + break; + case '*': + createSubMenu(); + default: + break; + } +} + +void createSubMenu() { + // Create the items + MenuItem myItems[4]; + + // Loop through list and add each item to the menu + for (uint8_t i = 0; i < 4; i++) { + // Create MenuItem to be added + MenuItem wifiParamsMenu[] = {MenuItem(names[i]), + ItemInput("Pass", "", NULL)}; + // Insert MenuItem into array + myItems[i] = + ItemSubMenu(names[i], menu.buildSubMenu(wifiParamsMenu, 2)); + } + + /** Set the submenu, (precise the position on the display and the items to + * use). Use the buildSubMenu function to generate a submenu following + * LcdMenu's style + */ + menu.setSubMenu(1, menu.buildSubMenu(myItems, 4)); +} \ No newline at end of file diff --git a/examples/MenuNotifications/MenuNotifications.ino b/examples/MenuNotifications/MenuNotifications.ino new file mode 100644 index 00000000..6e7095d3 --- /dev/null +++ b/examples/MenuNotifications/MenuNotifications.ino @@ -0,0 +1,61 @@ +#include +#include + +#define LCD_ROWS 2 +#define LCD_COLS 16 + +// Configure keypad keys +char keys[4][4] = {{'1', '2', '3', 'A'}, + {'4', '5', '6', 'B'}, + {'7', '8', '9', 'C'}, + {'*', '0', '#', 'D'}}; + +// Configure keypad pins +byte colPins[4] = {5, 4, 3, 2}; +byte rowPins[4] = {9, 8, 7, 6}; + +extern MenuItem mainMenu[]; +extern MenuItem settingsMenu[]; + +MenuItem mainMenu[] = {ItemHeader(), + MenuItem("Start service"), + MenuItem("Connect to WiFi"), + ItemSubMenu("Settings", settingsMenu), + MenuItem("Blink SOS"), + MenuItem("Blink random"), + ItemFooter()}; +/** + * Create submenu and precise its parent + */ +MenuItem settingsMenu[] = {ItemSubHeader(mainMenu), + MenuItem("Backlight"), + MenuItem("Contrast"), + ItemFooter()}; + +LcdMenu menu(LCD_ROWS, LCD_COLS); + +Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4); + +void setup() { menu.setupLcdWithMenu(0x27, mainMenu); } + +void loop() { + char key = keypad.getKey(); + if (key == NO_KEY) return; + + switch (key) { + case 'A': + menu.up(); + break; + case 'B': + menu.down(); + break; + case 'C': + menu.enter(); + break; + case 'D': + menu.back(); + break; + default: + break; + } +} \ No newline at end of file diff --git a/examples/MenuOne/MenuOne.ino b/examples/MenuOne/MenuOne.ino index d304b23e..60362219 100644 --- a/examples/MenuOne/MenuOne.ino +++ b/examples/MenuOne/MenuOne.ino @@ -1,5 +1,4 @@ #include -#include #include diff --git a/examples/SubMenu/SubMenu.ino b/examples/SubMenu/SubMenu.ino new file mode 100644 index 00000000..4635b1ce --- /dev/null +++ b/examples/SubMenu/SubMenu.ino @@ -0,0 +1,88 @@ +/* + Sub Menu + + This sketch demostrates how to create menus which contain other menus + + Circuit: + * Arduino Board + * Keypad pin 1 to digital pin 9 + * Keypad pin 2 to digital pin 8 + * Keypad pin 3 to digital pin 7 + * Keypad pin 4 to digital pin 6 + * Keypad pin 5 to digital pin 5 + * Keypad pin 6 to digital pin 4 + * Keypad pin 7 to digital pin 3 + * Keypad pin 8 to digital pin 2 + * LCD SLC pin to arduino SLC pin + * LCD SDA pin to arduino SDA pin + + created 22 July 2020 + by Forntoh Thomas + + This example is in the public domain. + + https://github.com/forntoh/LcdMenu/tree/master/examples/SubMenu/SubMenu.ino + +*/ + +#include +#include + +#define LCD_ROWS 2 +#define LCD_COLS 16 + +// Configure keypad keys +char keys[4][4] = {{'1', '2', '3', 'A'}, + {'4', '5', '6', 'B'}, + {'7', '8', '9', 'C'}, + {'*', '0', '#', 'D'}}; + +// Configure keypad pins +byte colPins[4] = {5, 4, 3, 2}; +byte rowPins[4] = {9, 8, 7, 6}; + +extern MenuItem mainMenu[]; +extern MenuItem settingsMenu[]; + +MenuItem mainMenu[] = {ItemHeader(), + MenuItem("Start service"), + MenuItem("Connect to WiFi"), + ItemSubMenu("Settings", settingsMenu), + MenuItem("Blink SOS"), + MenuItem("Blink random"), + ItemFooter()}; +/** + * Create submenu and precise its parent + */ +MenuItem settingsMenu[] = {ItemSubHeader(mainMenu), + MenuItem("Backlight"), + MenuItem("Contrast"), + ItemFooter()}; + +LcdMenu menu(LCD_ROWS, LCD_COLS); + +Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4); + +void setup() { menu.setupLcdWithMenu(0x27, mainMenu); } + +void loop() { + char key = keypad.getKey(); + if (key == NO_KEY) return; + + switch (key) { + case 'A': + menu.up(); + break; + case 'B': + menu.down(); + break; + case 'C': + menu.enter(); + break; + case 'D': + menu.back(); + break; + default: + break; + } +} \ No newline at end of file