I have a simple program with a problem I can't find an answer to. When a button is pressed on the TFT screen it shows at the bottom. I would also like it to send that info to the serial monitor. The sketch as below does this but free runs with a new repeat message every few milliseconds. I want a single line display.
If I un select the // Serial.end(); lines it does correct for the first button pressed but then there is no further output. I (obviously) wrongly thought that the break; line reverted to the situation before the "case"
was selected.
Can anyone help as I am getting very dry.
// My TFT sketch
//#include <TouchScreen.h>
#include <UTFT.h>
#include <URTouch.h>
#include <UTFT_Buttons.h>
extern uint8_t BigFont[];
UTFT myGLCD(CTE70, 38, 39, 40, 41); // was UTFT myGLCD(CTE70, 25, 26, 27, 28)for Due;
URTouch myTouch(6, 5, 4, 3, 2);
UTFT_Buttons myButtons(&myGLCD, &myTouch);
const int redLed = 10;
const int greenLed = 9;
const int blueLed = 8;
int but1, but2, but3, but4, but5, but6, but7, pressed_button;
void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(BigFont);
myTouch.InitTouch();
myTouch.setPrecision(PREC_LOW);
myButtons.setTextFont(BigFont);
Serial.begin(9600);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
}
void loop()
{
Serial.println("TEST TO MAKE SURE SERIAL WORKING");
boolean default_colors = false;
drawHomeScreen();
while (1)
{
if (myTouch.dataAvailable() == true)
pressed_button = myButtons.checkButtons();
switch (pressed_button) {
case 1:
myGLCD.print("Button 1", CENTER, 450);
Serial.println("Button 1");
//Serial.end();
break;
case 2:
myGLCD.print("Button 2", CENTER, 450);
Serial.println("Button 2");
//Serial.end();
break;
case 3:
myGLCD.print("Button 3", CENTER, 450);
Serial.println("Button 3");
// Serial.end();
break;
case 4:
myGLCD.print("Button 4", CENTER, 450);
Serial.println("Button 4");
// Serial.end();
break;
case 5:
myGLCD.print("Button 5", CENTER, 450);
Serial.println("Button 5");
// Serial.end();
break;
case 6:
myGLCD.print("Button 6", CENTER, 450);
Serial.println("Button 6");
//Serial.end();
break;
case 7:
myGLCD.print("Button 6", CENTER, 450);
Serial.println("Button 6");
// Serial.end();
break;
}
}
}
void drawHomeScreen() {
but1 = myButtons.addButton( 10, 5, 767, 40, "DOG HOUSE BAR");
but2 = myButtons.addButton( 10, 50, 767, 60, "Whiskey and Lemonade");
but3 = myButtons.addButton( 10, 115, 767, 60, "Gin and Tonic");
but4 = myButtons.addButton( 10, 180, 767, 60, "Rum and Coke");
but5 = myButtons.addButton( 10, 245, 767, 60, "Whiskey");
but6 = myButtons.addButton( 10, 310, 767, 60, "Tonic");
but7 = myButtons.addButton( 10, 375, 767, 60, "Coke");
myButtons.drawButtons();
}
Many thanks for reading this, and thanks for any advice>