Skip to content

Commit

Permalink
Embedded code into examples
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 9, 2021
1 parent 6e01daa commit c3a1382
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/Basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,48 @@ Go to [.../examples/Basic/Basic.ino](https://github.com/forntoh/LcdMenu/tree/mas

```cpp
// ../../examples/Basic/Basic.ino#L35-L77

// 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);

void setup() {
Serial.begin(9600);
// Initialize LcdMenu with the menu items
menu.setupLcdWithMenu(0x27, mainMenu);
}

void loop() {
if (!Serial.available()) return;
char command = Serial.read();

if (command == UP)
menu.up();
else if (command == DOWN)
menu.down();
else if (command == LEFT)
menu.left();
else if (command == RIGHT)
menu.right();
else if (command == ENTER)
menu.enter();
else if (command == BACK)
menu.back();
else if (command == CLEAR)
menu.clear();
else if (command == BACKSPACE)
menu.backspace();
else
menu.type(command);
}
```
18 changes: 18 additions & 0 deletions examples/Callbacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ Callbacks can be used with menu items of type `ItemCommand`, `ItemInput`, `ItemL

```cpp
// ../../examples/Callbacks/Callbacks.ino#L36-L36

void toggleBacklight(uint8_t isOn);
```
### 2. Add callback to MenuItem
```cpp
// ../../examples/Callbacks/Callbacks.ino#L51-L56
MenuItem settingsMenu[] = {ItemHeader(mainMenu),
//
// Include callback in ItemToggle
//
ItemToggle("Backlight", toggleBacklight),
MenuItem("Contrast"), ItemFooter()};
```

### 3. Define the callback function
Expand All @@ -31,6 +40,15 @@ When `enter()` is invoked, the command _(callback)_ bound to the item is invoked

```cpp
// ../../examples/Callbacks/Callbacks.ino#L88-L95

/**
* Define callback
*/
void toggleBacklight(uint8_t isOn) {
menu.lcd->setBacklight(isOn);
// Or this way
menu.toggleBacklight();
}
```
Full code 👉 [.../examples/Callbacks/Callbacks.ino](https://github.com/forntoh/LcdMenu/tree/master/examples/Callbacks/Callbacks.ino)
23 changes: 23 additions & 0 deletions examples/CharsetInput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ You also need to track the active index of the list

```cpp
// ../../examples/CharsetInput/CharsetInput.ino#L36-L40

#define CHARSET_SIZE 10
// Create your charset
char charset[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
// Active index of the charset
uint8_t charsetPosition;
```
### 2. Move to an ItemInput menu item
Expand All @@ -33,6 +39,20 @@ Execute `enter()` to go to edit mode. _(cursor will start blinking 😉)_
```cpp
// ../../examples/CharsetInput/CharsetInput.ino#L68-L80
case UP:
if (menu.isInEditMode()) // Update the position only in edit mode
charsetPosition = (charsetPosition + 1) % CHARSET_SIZE;
menu.drawChar(charset[charsetPosition]); // Works only in edit mode
menu.up();
break;
case DOWN:
if (menu.isInEditMode()) // Update the position only in edit mode
charsetPosition =
constrain(charsetPosition - 1, 0, CHARSET_SIZE);
menu.drawChar(charset[charsetPosition]); // Works only in edit mode
menu.down();
break;
```

### 5. Type the selected character
Expand All @@ -41,6 +61,9 @@ Use `menu.type(char character)` to type the selected character

```cpp
// ../../examples/CharsetInput/CharsetInput.ino#L87-L88

case ENTER: // Press enter to go to edit mode : for ItemInput
menu.type(charset[charsetPosition]); // Works only in edit mode
```

### 6. `menu.back()` will exit edit mode
Expand Down
12 changes: 12 additions & 0 deletions examples/List/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ The supported datatype for the list is `String`. This can be used for other prim

```cpp
// ../../examples/List/List.ino#L41-L41

extern String colors[];
```

### 2. Initialize the array

```cpp
// ../../examples/List/List.ino#L43-L44

String colors[] = {"Red", "Green", "Blue", "Orange",
"Aqua", "Yellow", "Purple", "Pink"};
```
### 3. Add the array to your `MenuItem`
Expand All @@ -31,6 +36,8 @@ You must add the size of the array in order for the menu to know when to stop or
```cpp
// ../../examples/List/List.ino#L58-L58
ItemList("Col", colors, 9, colorsCallback),
```

### 4. Cycle through list
Expand All @@ -46,6 +53,11 @@ When `enter()` is invoked, the command _(callback)_ bound to the item is invoked

```cpp
// ../../examples/List/List.ino#L97-L100

void colorsCallback(uint8_t pos) {
// do something with the index
Serial.println(colors[pos]);
}
```
Full example 👉 [.../examples/List/List.ino](https://github.com/forntoh/LcdMenu/tree/master/examples/List/List.ino)
8 changes: 8 additions & 0 deletions examples/SimpleInput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Use `menu.type(char character)` to type a character

```cpp
// ../../examples/SimpleInput/SimpleInput.ino#L74-L75

else // Type the character you want
menu.type(command);
```

### 2. Run when item is selected
Expand All @@ -25,6 +28,11 @@ When `enter()` is invoked, the command _(callback)_ bound to the item is invoked

```cpp
// ../../examples/SimpleInput/SimpleInput.ino#L80-L83

void inputCallback(String value) {
Serial.print(F("# "));
Serial.println(value);
}
```
Full example 👉 [.../examples/SimpleInput/SimpleInput.ino](https://github.com/forntoh/LcdMenu/tree/master/examples/SimpleInput/SimpleInput.ino)
17 changes: 17 additions & 0 deletions examples/SubMenu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@ This example will show you how to get started with submenus

```cpp
// ../../examples/SubMenu/SubMenu.ino#L39-L46

// Define the main menu
MenuItem mainMenu[] = {ItemHeader(),
MenuItem("Start service"),
MenuItem("Connect to WiFi"),
ItemSubMenu("Settings", settingsMenu),
MenuItem("Blink SOS"),
MenuItem("Blink random"),
ItemFooter()};
```
### 2 Create the sub menu
```cpp
// ../../examples/SubMenu/SubMenu.ino#L47-L53
/**
* Create submenu and precise its parent
*/
MenuItem settingsMenu[] = {ItemHeader(mainMenu), MenuItem("Backlight"),
MenuItem("Contrast"), ItemFooter()};
LcdMenu menu(LCD_ROWS, LCD_COLS);
```

Go to [.../examples/SubMenu/SubMenu.ino](https://github.com/forntoh/LcdMenu/tree/master/examples/SubMenu/SubMenu.ino)

0 comments on commit c3a1382

Please sign in to comment.