c. Defining & Using Tags

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 13 - Touch Primitives >

c. Defining & Using Tags

This section shows how to define and use tags.






void setup()


/* Initialize CleO */




void display()


 /* Start drawing the screen shot */


 CleO.StringExt(FONT_MEDIUM, 160, 50, LIGHT_GREEN, MM, 0, 0, "TOUCH OBJECTS");




 CleO.Line(105, 125, 225, 125);




 CleO.Point(160, 300);



 if (lineTouched)

   CleO.StringExt(FONT_MEDIUM, 160, 200, LIGHT_GREEN, MM, 0, 0,

   "Touching Line");


 if (pointTouched)

   CleO.StringExt(FONT_MEDIUM, 160, 400, LIGHT_GREEN, MM, 0, 0,

   "Touching Point");


/* Show the screenshot */




void control()


 int16_t x, y, dur, tag, newval;

 CleO.TouchCoordinates(x, y, dur, tag);

 if (tag == 1)

   lineTouched = true;

 else if (tag == 2)

   pointTouched = true;


   pointTouched = lineTouched = false;



void loop()









Using the Tag(int tag_no) routine, you can draw the CleO primitives which get assigned a tag.

This tag is used to identify touch on drawing.

The display() function draws a line with tag 1 and point with tag 2.

It checks whether these drawings are touched and if so, it creates an effect of a button press.

The control() routine checks for touch using the TouchCoordinates() command and fills up the tag value based on which drawing was touched.

It checks the tag value and updates the boolean to notify which drawing was affected.


Note: A tag is applicable on all the objects after which it is used. In this case, the object point (160,300) starts with tag 2 and ends with END tag 255.





Here is the output displayed upon executing the code snippet -


3 -DefiningAndUsingTags