Skip to content

Example 03: Party Hard!

Alexander Spiridonov edited this page May 17, 2024 · 17 revisions

Additional documentation for an example supplied with the GEM library that demonstrates creation of option select with callback (for preset selection), editable menu items with validation callbacks, setting readonly mode, creation of context with context.allowExit set to false in order to use push-buttons to control scene within context's loop.

About

This example demonstrates creation of one page menu with one editable menu item associated with int variable, one with bool variable, one option select, and a button, pressing of which will result in launch of animation sequence drawn to the screen. Delay between frames is determined by value of int variable, setting of which to 0 will enable manual control of the frames through navigation push-buttons.

Callback function is attached to option select to control the other variables based on selected option (thus creating sort of preset selector).

Another callback function is attached to menu item linked to int variable, making sure that variable is within allowable range.

Note that for Adafruit GFX version of this example it may be required to disable some extra features in config.h (e.g. support for editable floating-point variables) in order to fit in Arduino UNO R3 board.

Highlights

In this example it will be shown how to:

Schematic and Breadboard

This example relies on the Test bench configuration (AltSerialGraphicLCD version, U8g2 version and Adafruit GFX version).

Sketch

Annotated sketch (as well as additional file containing animation sprites) is supplied with the library and can be found at:

Simulator

Simulation of this example (using U8g2 version of GEM) is available on Wokwi. It is possible to interact with the simulation using mouse or keyboard: keys w, a, s, d, e, q are bound to the corresponding buttons on the breadboard (make sure to focus simulation window by clicking on it first).

Run

After compiling and uploading sketch to Arduino, wait while LCD screen boots and menu is being initialized and drawn to the screen. Then start pressing the push-buttons and navigate through the menu. Pressing "Ok" button (attached to pin 7) will trigger edit mode of the "Tempo" preset selector, or the "Interval" variable, or change state of "Strobe" option, or invoke action associated with "Let's Rock!" menu button.

Setting "Tempo" select to one of the available options will update the other variables accordingly (setting value and readonly mode of "Interval" variable as well as state of "Strobe" checkbox). Selecting "Custom" option will result in readonly mode of "Interval" disabled, thus allowing user to adjust its value directly. "Manual" mode will set "Interval" to 0, thus enabling manual navigation through animation frames (see below).

Setting "Interval" variable to the negative value (in "Custom" mode of the "Tempo" select) will result in it set to the value of 0 automatically.

Pressing "Let's Rock!" button will launch animation loop, consisting of 5 sprites consequently drawn to the screen with delay determined by the value of "Interval" variable (in ms). Setting "Interval" to 0 (or selecting "Manual" option from "Tempo" select) will enable manual navigation through animation frames by using "Left" and "Right" push-buttons (attached to pins 3 and 4 respectively).

Enabling "Strobe" mode will result in 2nd and 4th frames of the animation being drawn in inversed mode.

To exit animation loop press "Cancel" button (attached to pin 6).