"I am completely new to this arduino thing, but have hacked chopped and twisted, or otherwise managed to use a megaR3, with an Uno touch screen shield, (the blue board). I have managed to get it all working and now completely wrapped around the axel about debouncing the Touchscreen. No interest in Drawing but I would like to build a menu.
I found the "arduin_b_phone" code, stripped what I believe to be the fona stuff out, just to focus in on the debounce of the touchscreen . I believe my problem is centered around the "buttons**.drawButton(true); // draw invert!" line 164 referring to the library. I make the assumption that this represents or was intended to be a color change on the button, but my end result is a blue strip on my screen left of pressed button. I need to rerun setup to eliminate it. I could not find documentation about this Adafruit_GFX_Button " routine . I would like to understand this better .**
I also didn't get my text result to display in the top window, but not a concern at the moment because I'm thinking its also related.
Thank you
```
**#include <SPI.h>
#include <Wire.h> // this is needed even tho we aren't using it
#include <Adafruit_GFX.h> // Core graphics library
#include <AdaLGDP4535TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
// Touch setup
// These are the pins for the shield!
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
#define MINPRESSURE 10
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// TFT setup
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define BLACK 0x0000
#define GRAY 0x8410
#define WHITE 0xFFFF
#define RED 0xF800
#define ORANGE 0xFA60
#define YELLOW 0xFFE0
#define LIME 0x07FF
#define GREEN 0x07E0
#define CYAN 0x07FF
#define AQUA 0x04FF
#define BLUE 0x001F
#define MAGENTA 0xF81F
#define PINK 0xF8FF
//Adafruit_TFTLCD tft; //old
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 960 //920
#define TS_MINY 970 //940
#define TS_MAXX 130 //120
#define TS_MAXY 130 //120
/******************* UI details */
#define BUTTON_X 40
#define BUTTON_Y 100
#define BUTTON_W 60
#define BUTTON_H 30
#define BUTTON_SPACING_X 20
#define BUTTON_SPACING_Y 20
#define BUTTON_TEXTSIZE 2
// text box where numbers go
#define TEXT_X 10
#define TEXT_Y 10
#define TEXT_W 220
#define TEXT_H 50
#define TEXT_TSIZE 3
#define TEXT_TCOLOR MAGENTA
// the data (phone #) we store in the textfield
#define TEXT_LEN 12
char textfield[TEXT_LEN+1] = "";
uint8_t textfield_i=0;
/* create 15 buttons, in classic candybar phone style /
char buttonlabels[15][5] = {"Send", "Clr", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "", "0", "#" };
uint16_t buttoncolors[15] = {GREEN, GRAY, RED,
BLUE, BLUE, BLUE,
BLUE, BLUE, BLUE,
BLUE, BLUE, BLUE,
ORANGE, BLUE, ORANGE};
Adafruit_GFX_Button buttons[15];
void setup() {
Serial.begin(115200);
Serial.println("Arduin-o-Phone!");
tft.reset();
uint16_t identifier = tft.readID();
Serial.println(identifier, HEX);
tft.begin(identifier);
tft.fillScreen(BLACK);
Wire.begin();
Serial.println("Touchscreen started");
// create buttons
for (uint8_t row=0; row<5; row++) {
for (uint8_t col=0; col<3; col++) {
buttons[col + row3].initButton(&tft, BUTTON_X+col(BUTTON_W+BUTTON_SPACING_X),
BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
BUTTON_W, BUTTON_H, WHITE, buttoncolors[col+row3], WHITE,
buttonlabels[col + row3], BUTTON_TEXTSIZE);
buttons[col + row*3].drawButton();
}
}
Serial.println("Buttons Created");
// create 'text field'
tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, WHITE);
Serial.println("Text Field' Created");
Serial.println("End setup");
}
void loop(void) {
TSPoint p = ts.getPoint();
// if sharing pins, you'll need to fix the directions of the touchscreen pins
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
p = ts.getPoint();
} else {
// this is our way of tracking touch 'release'!
p.x = p.y = p.z = -1;
}
// Scale from ~0->4000 to tft.width using the calibration #'s
if (p.z != -1)
{
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
Serial.print("("); Serial.print("p.x");Serial.print(p.x); Serial.print(", ");
Serial.print("p.y");Serial.print(p.y); Serial.print(", ");
Serial.print("p.z");Serial.print(p.z); Serial.println(") ");
}
// go thru all the buttons, checking if they were pressed
for (uint8_t b=0; b<15; b++) {
if (buttons[b].contains(p.x, p.y)) {
// Serial.print("Pressing: "); Serial.println(b);
buttons[b].press(true); // tell the button it is pressed
} else {
buttons[b].press(false); // tell the button it is NOT pressed
}
}
// now we can ask the buttons if their state has changed
for (uint8_t b=0; b<15; b++) {
if (buttons[b].justReleased()) {
// Serial.print("Released: "); Serial.println(b);
buttons[b].drawButton(); // draw normal
}
if (buttons[b].justPressed()) {
buttons[b].drawButton(true); // draw invert!
// if a numberpad button, append the relevant # to the textfield
if (b >= 3) {
if (textfield_i < TEXT_LEN) {
textfield[textfield_i] = buttonlabels[b][0];
textfield_i++;
textfield[textfield_i] = 0; // zero terminate
}
Serial.print("Array button No ");Serial.println(b);
}
// clr button! delete char
if (b == 1) {
textfield[textfield_i] = 0;
if (textfield > 0) {
textfield_i--;
textfield[textfield_i] = ' ';
}
Serial.print("Clear ");Serial.println(b);
}
/*
// update the current text field
Serial.print("textfield ");Serial.println(textfield);
Serial.print("TEXT_X ");Serial.println(TEXT_X);
Serial.print("TEXT_Y+10 ");Serial.println(TEXT_Y+10);
tft.setCursor(TEXT_X + 2, TEXT_Y+10);
tft.setTextColor(WHITE,GREEN);
tft.setTextSize(3);
tft.print(textfield);
tft.setCursor(TEXT_X + 2, TEXT_Y+10);
tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
tft.setTextSize(TEXT_TSIZE);
tft.print(textfield);
// its always OK to just hang up
if (b == 2) {
Serial.print("Hangup "); Serial.print(textfield);
}
if (b == 0) {
Serial.print("Calling "); Serial.print(textfield);
}
/
delay(100); // UI debouncing
}
}
}*
```