Skip to content

Commit

Permalink
added notification example
Browse files Browse the repository at this point in the history
  • Loading branch information
forntoh committed Jul 23, 2020
1 parent ae3e11e commit 9e09ddb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ See [Wiki - Callbacks](https://github.com/forntoh/LcdMenu/wiki/Example-03-Callba

### 04 Dynamic Menus

See [Wiki - Dynamic Menu](https://github.com/forntoh/LcdMenu/wiki/Example-04-Dynamic-Menu)
See [Wiki - Dynamic Menu](https://github.com/forntoh/LcdMenu/wiki/Example-04-Dynamic-Menu)

### 05 Menu Notifications

See [Wiki - Menu Notifications](https://github.com/forntoh/LcdMenu/wiki/Example-05-Menu-Notifications)
1 change: 1 addition & 0 deletions examples/DynamicMenu/DynamicMenu.ino
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void loop() {
break;
case '*':
createSubMenu();
break;
default:
break;
}
Expand Down
60 changes: 48 additions & 12 deletions examples/MenuNotifications/MenuNotifications.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
/*
Menu Notifications
This sketch demostrates how to display Notifications
using the LcdMenu library. After the specified time, the notification message
disappears. In this sketch When the # key is pressed, the notification displays
for two (2) seconds
N.B: You must call menu.updateTimer(); in the first line of the loop function
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/MenuNotifications/MenuNotifications.ino
*/

#include <Keypad.h>
#include <LcdMenu.h>

Expand All @@ -9,28 +41,19 @@ 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("Settings"),
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);

Expand All @@ -39,6 +62,13 @@ Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4);
void setup() { menu.setupLcdWithMenu(0x27, mainMenu); }

void loop() {
/**
* IMPORTANT: You must call this function for the notification to take time
* into account
*/
menu.updateTimer();

// Listen to key
char key = keypad.getKey();
if (key == NO_KEY) return;

Expand All @@ -55,7 +85,13 @@ void loop() {
case 'D':
menu.back();
break;
case '#':
// When the # key is pressed, the message displays for two seconds
showNotification();
break;
default:
break;
}
}
}

void showNotification() { menu.displayNotification("Success", 2000); }

0 comments on commit 9e09ddb

Please sign in to comment.