|Description||ViSi-Genie Magic Slide to Unlock shows how a stand-alone ViSi-Genie program with a slide-to-unlock feature is created. The slide-to-unlock project has two forms.|
|Supported Processor||PICASO, DIABLO16|
This application note shows how to write a sketch for an Arduino program that handles REPORT_EVENT messages coming from the display module.
Note 1: Workshop Pro is needed for this application.
Before getting started, the following are required:
- Any of the following 4D Picaso display modules:
and other superseded modules which support the ViSi Genie environment
- The target module can also be a Diablo16 display
Visit www.4dsystems.com.au/products to see the latest display module products that use the Diablo16 processor.
- 4D Programming Cable or µUSB-PA5
- micro-SD (µSD) memory card
- Workshop 4 IDE (installed according to the installation document)
- An Arduino board with a UART serial port
- 4D Arduino Adaptor Shield (optional) or connecting wires
- Arduino IDE
- When downloading an application note, a list of recommended application notes is shown. It is assumed that the user has read or has a working knowledge of the topics presented in these recommended application notes.
To understand this application note more quickly, the reader is advised to read and understand first the following application notes.
ViSi-Genie Magic Slide to Unlock shows how a stand-alone ViSi-Genie program with a slide-to-unlock feature is created. The slide-to-unlock project has two forms. The first form has a slider whose knob, when dragged to and released on the right-most part, triggers the program to navigate to the second form. A winbutton on the second form, when pressed, causes the program to navigate back to the first form.
ViSi-Genie Magic Slide to Unlock with a Host discusses an improved version of the project in ViSi-Genie Magic Slide to Unlock, such that when the knob of the slider is moved to and released on the extreme right (the program is unlocked), a message is sent to the serial port. Also, when the winbutton on the second form is pressed (the program is locked), another message is sent to the serial port.
At this point, it is assumed that the reader has a working setup of the project described in the application note ViSi-Genie Magic Slide to Unlock with a Host. The remaining task now is to write the sketch for the Arduino program and upload the program to the Arduino host.
A thorough understanding of the application note ViSi-Genie Connecting a 4D Display to an Arduino Host is required before attempting to proceed further beyond this point. ViSi-Genie Connecting a 4D Display to an Arduino Host provides all the basic information that a user needs to be able to get started with ViSi-Genie and Arduino. The following is a list of the topics discussed in ViSi-Genie Connecting a 4D Display to an Arduino Host.
- How to download and install the ViSi-Genie-Arduino library
- How to open a serial port for communicating with the display and how to set the baud rate
- The genieAttachEventHandler() function
- How to reset the host and the display
- How to set the screen contrast
- How to send a text string
- The main loop
- Receiving data from the display
- The use of a non-blocking delay in the main loop
- How to change the status of an object
- How to know the status of an object
- The user’s event handler
Discussion of any of these topics is avoided in other ViSi-Genie-Arduino application notes unless necessary. Users are encouraged to read ViSi-Genie Connecting a 4D Display to an Arduino Host first.
Open the sketch “slideToUnlockSS” attached to this document.
- Assignment of the software serial pins. This is actually prior to the setup routine. Visit the Arduino website for more information about the SoftwareSerial library.
- Initialization of serial communication
- Reset routine (this is important)
This is the conditional block shown below.
This block runs in approximately every 500 ms. The user can increase the frequency of execution of this block by changing the literal constant “500” to another value. The block above does nothing except to update value of the variable “waitPeriod”. As indicated above, this is where the user can insert other lines for the sketch. The above is an implementation of the “non-blocking” delay method. When writing an Arduino sketch that communicates with a 4D display using the ViSi-Genie-Arduino library, it is best to use a non-blocking delay instead of a “blocking delay”. A blocking delay usually makes use of the function “delay(period in ms)”. The use of a blocking delay is not ideal since the processor does nothing for the duration of the delay period. The method “genie.DoEvents()” of the ViSi-Genie-Arduino library has timing-sensitive processes that run in the background. Blocking delays, therefore, tend to prevent the execution of the internal processes of the ViSi-Genie-Arduino library. Consequences include programs that seem to run very slowly or messages coming from the display being lost. This explains why the use of a non-blocking delay is preferred. For more information on blocking and non-blocking delays, visit the Arduino community.
This method executes the internal processes of the library, one of which is the queueing of events or messages coming from the display. This method also executes the user-defined event handler “myGenieEventHandler()”.
This is the user-defined event handler. It takes a message from the queue and evaluates it in a manner which is to be defined by the user.
For this application, the event handler performs the following steps (as indicated above).
- Take a message or an event from the queue of events.
- Evaluate if the event is a REPORT_EVENT message.
- Extract the index from the message. This is the index of the object which triggered the sending of the message.
- Evaluate if the event comes from a form object.
- If the event comes from a form object, the index therefore identifies which form on the display has been activated. The correct information is then printed.
Refer to the section “Connect the Display Module to the Arduino Host” of the application note “ViSi-Genie Connecting a 4D Display to an Arduino Host” for the following topics:
- Using the New 4D Arduino Adaptor Shield (Rev 2.00)
- Definition of Jumpers and Headers
- Default Jumper Settings
- Change the Arduino Host Serial Port
- Power the Arduino Host and the Display Separately
- Using the Old 4D Arduino Adaptor Shield (Rev 1)
- Connection Using Jumper Wires
- Changing the Serial port of the Genie Program
- Changing the Maximum String Length
Note: The attached Arduino sketch uses a software serial port to communicate with the display module and a hardware serial port to communicate with Serial Monitor running on the PC.