Skip to content

Commit

Permalink
added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
forntoh committed Jul 23, 2020
1 parent 4485cb3 commit aba43ff
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
See [Wiki - Submenus](https://github.com/forntoh/LcdMenu/wiki/Submenus)
42 changes: 37 additions & 5 deletions examples/Basic/Basic.ino
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
/*
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 <Keypad.h>
#include <LcdMenu.h>

#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"),
MenuItem("Settings"),
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();
Expand Down
99 changes: 99 additions & 0 deletions examples/Callbacks/Callbacks.ino
Original file line number Diff line number Diff line change
@@ -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 <Keypad.h>
#include <LcdMenu.h>

#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); }
104 changes: 104 additions & 0 deletions examples/DynamicMenu/DynamicMenu.ino
Original file line number Diff line number Diff line change
@@ -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 <Keypad.h>
#include <LcdMenu.h>

#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));
}
61 changes: 61 additions & 0 deletions examples/MenuNotifications/MenuNotifications.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <Keypad.h>
#include <LcdMenu.h>

#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;
}
}
1 change: 0 additions & 1 deletion examples/MenuOne/MenuOne.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <Keypad.h>
#include <Timer.h>

#include <LcdMenu.h>

Expand Down
Loading

0 comments on commit aba43ff

Please sign in to comment.