|Description||This application note is a step by step procedure that explains the necessary coding practices required to enable and utilise the touch abilities on selected display modules.|
|Supported Processor||PICASO, DIABLO16|
|Supported Environment||Designer, ViSi|
This Application Note explores the possibilities provided by the ViSi-Genie environment in Workshop to work with an Arduino host. In this example, the host is an AVR ATmega328 microcontroller-based Arduino Uno board. The host can also be an Arduino Mega 2560 or Due. Ideally, the application described in this document should work with any Arduino board with at least one UART serial port. See specifications of Aduino boards here. 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
- 4D Programming Cable / µUSB-PA5/uUSBPA5-II
for non-gen4 displays (uLCD-xxx)
- 4D Programming Cable & gen4-IB / 4D-UPA / gen4-PA
for gen4 displays (gen4-uLCD-xxx)
- micro-SD (µSD) memory card
- Workshop 4 IDE (installed according to the installation document)
- Any 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.
A dominant standout feature of certain 4D display modules is their ability to enable touch detection. This application note is a step by step procedure that explains the necessary coding practices required to enable and utilise the touch abilities on selected PICASO display modules.
For instructions on how to launch Workshop 4, how to open a Designer project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note
For instructions on how to launch Workshop 4, how to open a ViSi project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note
For instructions on how to create a new Designer project, please refer to the section “Create a New Project” of the application note
For instructions on how to create a new ViSi project, please refer to the section “Create a New Project” of the application note
Layout the necessary scaffold for the program, which contains the following essential functions:
At the start of the program, insert the following function to enable the Touch feature:
This touch_Set() function can also be used to disable touch detection at any stage if required, by changing the inserted variable.
Now that touch has been enabled, it needs to be refined to a specific area of the screen. Generally speaking, applications will require a different action for a touch in certain areas. If this is not so, the entire screen can be used as the touch detection region. It should be noted that setting a specific touch detection region can be done in one of two ways. The following two sections cover the first approach. To set a specific touch region using an explicit command, use the following code:
touch_DetectRegion(x1, y1, x2, y2);
Insert the desired parameters for the X and Y coordinates of the screen. For example; if a screen with a resolution of 240x320 is being used, then the X and Y figures must lie within these bounds. The next two lines explicitly show the touch boundaries for detection being set.
touch_DetectRegion(0, 0, 240, 320); //enable entire area
touch_DetectRegion(10, 10, 30, 30); //enable a small 20x20 square
An alternative method to enable the entire active area can be done in one command. This method is recommended over manually setting the detection region to the same area as the screen resolution. Use the following command:
Now that the touch detection area has been set, it needs to be constantly checked for a change in state, or a ‘touch’. The status of a touch response is retrieved by using the following command:
Using the touch_Get() function returns a value depending on the current state. Integers 0 to 3 or their MACRO equivalents are returned based on the following results:
0 = NOTOUCH
1 = TOUCH_PRESSED
2 = TOUCH_RELEASED
3 = TOUCH_MOVING
In this way, it can be determined when there is activity on the screen.
The example program below sets a detection region right in the middle of the screen that is a 20x20 square region. This means that all other areas of the screen are disabled.
It can be difficult to use the above method of specifying explicit touch coordinates for a given area if there are multiple points on a screen that require a different action from a touch response. To scan for touch in multiple areas, the entire active area should be enabled and used in conjunction with a series of ‘if’ statements that each check for touch according to certain coordinates. The following example illustrates this concept. Five targets are drawn on the screen. Touch is then scanned in their locations, which upon activity will display the appropriate message verification.
A fully developed application below illustrates detecting touch in multiple regions on the screen using a switch statement for control flow. There are associated print statements and targets displayed on the screen to assist with experimenting with touch coordinate detection.
For instructions on how to save a Designer project, how to connect the target display to the PC, how to select the program destination, and how to compile and download a program, please refer to the section “Run the Program” of the application note
For instructions on how to save a ViSi project, how to connect the target display to the PC, how to select the program destination (this option is not available for Goldelox displays), and how to compile and download a program, please refer to the section “Run the Program” of the application note
The uLCD-32PTU and/or uLCD-35DT display modules are commonly used as examples, but the procedure is the same for other displays.