Post by dl14 on Sept 14, 2016 14:17:26 GMT -8
I am attempting to understand the touch input of the TFT in order to create a program with multiple buttons and labels, etc.
I start by creating two rectangles on the screen, when I wanted to test them responding to touch, I first attempted by giving them a tag and using GD.inputs.tag to handle a press on the rectangle. When nothing happened, I printed this variable out on my Serial Monitor and it is always either 0 or 255...
Next I attempted to understand the layout of the pixels given that it's a 480 x 272 screen. While in the Gameduino 2 book it says that GD.inputs.x and GD.inputs.y should return a value between 0 and 479 and 0 and 271 respectively, I found that the top left of the screen is coordinate (980, 40) and the bottom right is (25, 975). The top right is (25, 40) and the bottom left is (980, 975). (These are all rough values as they change often when I hold a press on the corner). I get these values by printing to the serial monitor.
I need help in making sense of these values and understand the best way to go about in handling touch presses on buttons!
Thanks!!
Below is my code:
#include <EEPROM.h>
#include <SPI.h>
#include <GD2.h>
void setup()
{
Serial.begin(9600);
GD.begin(0);
GD.Clear();
GD.cmd_gradient(0,0,0x6666ff,0,271,0xffffff);
GD.ColorRGB(0xFFFFFF);
GD.Begin(RECTS);
GD.LineWidth(10 * 16); // corner radius 10.0 pixels
GD.Tag(10);
GD.Vertex2ii(30, 30);
GD.Vertex2ii(200, 60);
GD.Tag(11);
GD.Vertex2ii(30, 100);
GD.Vertex2ii(200, 130);
GD.ColorRGB(0x000000);
GD.cmd_text(115, 45, 29, OPT_CENTER, "Hello");
GD.cmd_text(115, 115, 29, OPT_CENTER, "World");
GD.swap();
}
void loop()
{
GD.get_inputs();
if(GD.inputs.y != -32768 && GD.inputs.x != -32768){
Serial.print(GD.inputs.x);
Serial.print("\t\t");
Serial.print(GD.inputs.y);
Serial.print("\t\t");
Serial.print(GD.inputs.tag);
Serial.print("\n");
//Serial.print(GD.inputs.y);
}
//this was my first attempt which did not work when using the tag
/*if(GD.inputs.tag == 10){
GD.Clear();
GD.cmd_text(115, 45, 29, OPT_CENTER, "Hi!");
GD.swap();
}*/
}
I start by creating two rectangles on the screen, when I wanted to test them responding to touch, I first attempted by giving them a tag and using GD.inputs.tag to handle a press on the rectangle. When nothing happened, I printed this variable out on my Serial Monitor and it is always either 0 or 255...
Next I attempted to understand the layout of the pixels given that it's a 480 x 272 screen. While in the Gameduino 2 book it says that GD.inputs.x and GD.inputs.y should return a value between 0 and 479 and 0 and 271 respectively, I found that the top left of the screen is coordinate (980, 40) and the bottom right is (25, 975). The top right is (25, 40) and the bottom left is (980, 975). (These are all rough values as they change often when I hold a press on the corner). I get these values by printing to the serial monitor.
I need help in making sense of these values and understand the best way to go about in handling touch presses on buttons!
Thanks!!
Below is my code:
#include <EEPROM.h>
#include <SPI.h>
#include <GD2.h>
void setup()
{
Serial.begin(9600);
GD.begin(0);
GD.Clear();
GD.cmd_gradient(0,0,0x6666ff,0,271,0xffffff);
GD.ColorRGB(0xFFFFFF);
GD.Begin(RECTS);
GD.LineWidth(10 * 16); // corner radius 10.0 pixels
GD.Tag(10);
GD.Vertex2ii(30, 30);
GD.Vertex2ii(200, 60);
GD.Tag(11);
GD.Vertex2ii(30, 100);
GD.Vertex2ii(200, 130);
GD.ColorRGB(0x000000);
GD.cmd_text(115, 45, 29, OPT_CENTER, "Hello");
GD.cmd_text(115, 115, 29, OPT_CENTER, "World");
GD.swap();
}
void loop()
{
GD.get_inputs();
if(GD.inputs.y != -32768 && GD.inputs.x != -32768){
Serial.print(GD.inputs.x);
Serial.print("\t\t");
Serial.print(GD.inputs.y);
Serial.print("\t\t");
Serial.print(GD.inputs.tag);
Serial.print("\n");
//Serial.print(GD.inputs.y);
}
//this was my first attempt which did not work when using the tag
/*if(GD.inputs.tag == 10){
GD.Clear();
GD.cmd_text(115, 45, 29, OPT_CENTER, "Hi!");
GD.swap();
}*/
}