-
Notifications
You must be signed in to change notification settings - Fork 36
Example 02: Blink
Additional documentation for an example supplied with the GEM library that demonstrates creation of submenu, validation callback and button actions with custom context.
This example demonstrates creation of two page menu with one editable menu item associated with int
variable, one with char[17]
variable, and two buttons, pressing of which will result in blinking with internal LED: one button will launch delay()
based routine and create context with context.allowExit
set to true
, and the second one - millis()
based routine with context.allowExit
set to false
, that will require manual exit from the context's loop with explicit call to context.exit()
routine.
Callback function is attached to menu item linked to int
variable, making sure that variable is within allowable range.
In this example it will be shown how to:
- create editable menu item associated with
int
variable; - create editable menu item associated with
char[17]
variable; - create submenu;
- create button with context-based action.
This example relies on the Test bench configuration described here.
Annotated sketch is supplied with the library and can be found at "examples/Example-02_Blink/Example-02_Blink.ino".
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 "Interval" or "Label" variable, or invoke action associated with "Blink v1" and "Blink v2" menu buttons.
Setting "Interval" variable to the value less then 50 will result in it set to the value of 50 automatically. Launching then one of the "Blink" actions will result in internal LED of Arduino board blink with specified interval (in ms). Text on the screen of LCD, defined by the "Label" variable, will blink as well.
To exit Blink loop press "Cancel" button (attached to pin 6).
delay()
based Blink ("Blink v1" button) makes it harder to exit the loop due to the blocking nature of the delay()
function - carefully match timing of exit key presses with the blink cycles. millis()
based blink ("Blink v2" button) has no such restriction - program flow is not paused and key press allows to exit Blink routine immediately.
- Test bench (push-buttons):
- Example 01: Basic
- Example 02: Blink
- Example 03: Party Hard!
- Test bench (rotary encoder):
- Example 05: Encoder
- Example 06: Todo List