Touch Panel Library

The mikroBasic PRO for ARM provides a library for working with Touch Panel.

Library Dependency Tree

Touch Panel Library Dependency Tree

External dependencies of Touch Panel Library

Stellaris

The following variables must be defined in all projects using Touch Panel Library: Description : Example :
dim DriveA as sbit sfr external DriveA line. dim DriveA as sbit at GPIO_PORTB_DATA4_bit
dim DriveB as sbit sfr external DriveB line. dim DriveB as sbit at GPIO_PORTE_DATA0_bit
dim DriveA_Direction as sbit sfr external Direction of the DriveA pin. dim DriveA_Direction as sbit at GPIO_PORTB_DIR4_bit
dim DriveB_Direction as sbit sfr external Direction of the DriveB pin. dim DriveB_Direction as sbit at GPIO_PORTE_DIR0_bit

STM32

The following variables must be defined in all projects using Touch Panel Library: Description : Example :
dim DriveA as sbit sfr external DriveA line. dim DriveA as sbit at GPIOB_ODR.B1
dim DriveB as sbit sfr external DriveB line. dim DriveB as sbit at GPIOB_ODR.B0

Library Routines

TP_Init

Prototype

sub procedure TP_Init(dim display_width as word, dim display_height as word, dim readX_ChNo as byte, dim readY_ChNo as byte)

Description

Initialize touch panel display. Default touch panel ADC threshold value is set to 3900.

Parameters
  • display_width: set display width.
  • display_height: set display height.
  • readX_ChNo: read X coordinate from desired ADC channel.
  • readY_ChNo: read Y coordinate from desired ADC channel.
Returns

Nothing.

Requires

Before calling this function initialize ADC module.

Example
ADC1_Init()               ' Initalize ADC module
TP_Init(128, 64, 6, 7)    ' Initialize touch panel, dimensions 128x64
Notes

None.

TP_Set_ADC_Threshold

Prototype

sub procedure TP_Set_ADC_Threshold(dim threshold as word)

Description

Set custom ADC threshold value, call this function after TP_Init.

Parameters
  • threshold: custom ADC threshold value.
Returns

Nothing.

Requires

TP_Init has to be called before using this routine.

Example
TP_Set_ADC_Threshold(3900)    ' Set touch panel ADC threshold
Notes

None.

TP_Press_Detect

Prototype

sub function TP_Press_Detect() as byte

Description

Detects if the touch panel has been pressed.

Parameters

None.

Returns
  • 1 - if touch panel is pressed.
  • 0 - otherwise.
Requires

External dependencies of the library from the top of the page must be defined before using this function.

Example

Stellaris

' Touch Panel module connections
dim DriveA as sbit at GPIO_PORTB_DATA4_bit
    DriveB as sbit at GPIO_PORTE_DATA0_bit
    DriveA_Direction as sbit at GPIO_PORTB_DIR4_bit
    DriveB_Direction as sbit at GPIO_PORTE_DIR0_bit
' End Touch Panel module connections

if (TP_Press_Detect() <> 0) then
  ...
end if

STM32

' Touch Panel module connections
dim DriveA as sbit at GPIOB_ODR.B1
    DriveB as sbit at GPIOB_ODR.B0
' End Touch Panel module connections

if (TP_Press_Detect() <> 0) then
  ...
end if
Notes

None.

TP_Get_Coordinates

Prototype

sub function TP_Get_Coordinates(dim byref x_coordinate as word, dim byref y_coordinate as word) as byte

Description

Get touch panel coordinates and store them in x_coordinate and y_coordinate parameters.

Parameters
  • x_coordinate: x coordinate of the place of touch.
  • y_coordinate: y coordinate of the place of touch.
Returns
  • 0 - if reading is within display dimension range.
  • 1 - if reading is out of display dimension range.
Requires

Nothing.

Example
if (TP_Get_Coordinates(@x_coord, @y_coord) = 0) then
  ...
end if
Notes

None.

TP_Calibrate_Bottom_Left

Prototype

sub procedure TP_Calibrate_Bottom_Left()

Description

Calibrate bottom left corner of the touch Panel.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
TP_Calibrate_Bottom_Left()    ' Calibration of bottom left corner
Notes

None.

TP_Calibrate_Upper_Right

Prototype

sub procedure TP_Calibrate_Upper_Right()

Description

Calibrate upper right corner of the touch Panel.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example
TP_Calibrate_Upper_Right()    ' Calibration of upper right corner
Notes

None.

TP_Get_Calibration_Consts

Prototype

sub procedure TP_Get_Calibration_Consts(dim byref x_min as word, dim byref x_max as word, dim byref y_min as word, dim byref y_max as word)

Description

Gets calibration constants after calibration is done and stores them in x_min, x_max, y_min and y_max parameters.

Parameters
  • x_min: x coordinate of the bottom left corner of the working area.
  • x_max: x coordinate of the upper right corner of the working area.
  • y_min: y coordinate of the bottom left corner of the working area.
  • y_max: y coordinate of the upper right corner of the working area.
Returns

Nothing.

Requires

Nothing.

Example
TP_Get_Calibration_Consts(@x_min, @y_min, @x_max, @y_max)    ' Get calibration constants
Notes

None.

TP_Set_Calibration_Consts

Prototype

sub procedure TP_Set_Calibration_Consts(dim x_min as word, dim x_max as word, dim y_min as word, dim y_max as word)

Description

Sets calibration constants.

Parameters
  • x_min: x coordinate of the bottom left corner of the working area.
  • x_max: x coordinate of the upper right corner of the working area.
  • y_min: y coordinate of the bottom left corner of the working area.
  • y_max: y coordinate of the upper right corner of the working area.
Returns

Nothing.

Requires

Nothing.

Example
TP_Set_Calibration_Consts(148, 3590, 519, 3370)    ' Set calibration constants
Notes

None.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code