Hi
i am using a Mega2560 R3 i have got a sketch that used an lcd but i have got a TFT Display
am trying to get the sketch to show 4 different text outputs but all in the same place on the screen, ihave got the sketch to work with case statments and it works but the text are all mixed on top of each other,
heres the code:
#include <Wire.h>
#include <EEPROM.h>
#include <TFT_HX8357.h> // Hardware-specific library
TFT_HX8357 tft = TFT_HX8357(); // Invoke custom library
#include "z_Free_Fonts.h" // Include the header file attached to this sketch
#define TFT_GREY1 0x8410 // New colour // HERE WE CORRECT THE GRAY COLOR !!!!! 11 0x8410 - GREEN LABEL 0x39E7 - YELLOW LABEL
const int audioSwitchPin = A11; // set up a constant for the Audio Filter switch
int audioSwitchState = 0; // variable to hold the value of the switchPin
int prevaudioSwitchState = 0; // variable to hold previous value of the switchpin
int buttonPushCounter = 0; // counter for the number of button presses //audiobuttonPushCounter
void setup() { // put your setup code here, to run once:
//Wire.begin();
pinMode(audioSwitchPin,INPUT_PULLUP); // set up the switch pin as an input
digitalWrite(audioSwitchPin, HIGH); // turn on pullup resistor
// display.clearDisplay();
//********* Setup Filter Outputs ************
pinMode(A12, OUTPUT); //Initiates off pin
pinMode(A13, OUTPUT); //Initiates 1.5Khz pin
pinMode(A14, OUTPUT); //Initiates 2.0Khz pin
pinMode(A15, OUTPUT); //Initiates 2.5Khz pin
//***************** display setting ************************
tft.init();
tft.setRotation(1); //3// 1 WORKS
tft.fillScreen(0x0000); // erase everything
//default_settings ();
//tft.fillRoundRect(72, 45, 55, 23, 5, TFT_WHITE);tft.setCursor(80, 62, 1);tft.println("ATT");}
//{tft.fillRoundRect(72, 45, 55, 23, 5, TFT_GREY1);tft.setCursor(80, 62, 1);tft.println("ATT");}
//menu (); // go to the service menu
//**************** PERMANENT INFO DISPLAY PROGRAM ****************
tft.fillScreen(TFT_BLACK);
tft.fillRect(225, 108, 48, 23, TFT_WHITE); // стираем старое x y width hight //(355, 117, 90, 23, TFT_BLACK)
tft.setTextColor(TFT_WHITE );
tft.setFreeFont(FF6);
//temp1= 56; // x coordinate
//tft.setTextColor(TFT_WHITE);
//tft.setFreeFont(FF33);//21
//tft.fillRect(+70 , 265, 21, 3, TFT_BLACK); //erase the line for numbers
//tft.fillRect(+150 , 265, 21, 3, TFT_BLACK);
//tft.fillRect(+230 , 265, 21, 3, TFT_BLACK);
//tft.fillRect(+310 , 265, 21, 3, TFT_BLACK);
//************************************************************
tft.setCursor(152, 150, 1);// 285, 139, 1 //152, 150, 1
tft.println("MODE");
//tft.setCursor(285, 106, 1); //292, 106, 1
//tft.println("RIT ");
tft.setCursor(152, 125, 1);
tft.println("AUDIO"); // testing
//tft.setFreeFont(FF41); // 21
//tft.setCursor(10, 182, 1);
//tft.println("VCC - V");
tft.setFreeFont(FF26);//6
tft.drawRoundRect(140, 15, 334, 143, 5,TFT_BLUE); //x y width high radius color rectangle A
}
void loop() { // put your main code here, to run repeatedly:
audioSwitchState = digitalRead(audioSwitchPin); // check the status of the switc
if (audioSwitchState != prevaudioSwitchState) // compare the switchState to its previous state
{
if (audioSwitchState == LOW) // If the switch is pressed, count the press
{
buttonPushCounter ++;
buttonPushCounter %= 4;
}
}
switch (buttonPushCounter)
{
case 0: // Off
tft.setCursor(230, 125, 1); // SetCursor(230, 125, 1);
tft.setTextColor(TFT_BLACK); // Set up text color
tft.setFreeFont(FF29); // Set up Font Size
tft.println("OFF"); // print to display ("OFF")
digitalWrite(A12, HIGH); // Output on
digitalWrite(A13, LOW); // Output off
digitalWrite(A14, LOW); // Output off
digitalWrite(A15, LOW); // Output off
break;
case 1: // 1.5Khz
tft.setCursor(275, 125, 1); // SetCursor(0, 0);
tft.setTextColor(TFT_GREEN); // Set up text color
tft.setFreeFont(FF29); // Set up Font Size
tft.println("1.5K"); // print to display ("1.5K")
digitalWrite(A12, LOW); // Output off
digitalWrite(A13, HIGH); // Output on
digitalWrite(A14, LOW); // Output off
digitalWrite(A15, LOW); // Output off
break;
case 2: // 2.0Khz
tft.setCursor(325, 125, 1); // SetCursor(0, 0);
tft.setTextColor(TFT_RED); // Set up text color
tft.setFreeFont(FF29); // Set up Font Size
tft.println("2.0K"); // print to display ("2.0K")
digitalWrite(A12, LOW); // Output off
digitalWrite(A13, LOW); // Output off
digitalWrite(A14, HIGH); // Output on
digitalWrite(A15, LOW); // Output off
break;
case 3: // 2.5Khz
tft.setCursor(375, 125, 1); // SetCursor(0, 0);
tft.setTextColor(TFT_YELLOW); // Set up text color
tft.setFreeFont(FF29); // Set up Font Size
tft.println("2.5K"); // print to display ("2.5K")
digitalWrite(A12, LOW); // Output off
digitalWrite(A13, LOW); // Output off
digitalWrite(A14, LOW); // Output off
digitalWrite(A15, HIGH); // Output on
break;
}
prevaudioSwitchState = audioSwitchState; // save the current switch state as the last state
}