Text orientation is not working correctly

The text orientation is not working correctly



Using 2.8 inch TFT Touch Shield v2.0 (seeedstudio)



Below is my code. Every time I clear the screen the text direction is getting reversed and self corrects itself randomly. Any suggestions, please.



#include <HID.h>

#include <SPI.h>

#include <stdint.h>

#include <TFTv2.h>



TextOrientation orientation = LANDSCAPE_UPSIDE_DOWN;

char volt[] = " mVs";

const float delayTime = 2000;



void setup() {

TFT_BL_ON; // turn on the background light

Tft.TFTinit(); // init TFT library

Tft.fillScreen(0, 240, 0, 320, WHITE);

Serial.begin(9600);

}



void loop() {

orientation = LANDSCAPE_UPSIDE_DOWN;

Serial.print(“Blue zone”);

clear_display();

draw_blue_zone(5, 42);

draw_voltage(2000);

delay(delayTime);



Serial.print(“Green zone”);

clear_display();

draw_green_zone(25, 82);

draw_voltage(4000);

delay(delayTime);



Serial.print(“Red zone”);

clear_display();

draw_red_zone(45, 122);

draw_voltage(6000);

delay(delayTime);

}



void draw_red_zone(float tempCelcius, float tempFh)

{

//int drawString(char *string, int poX, int poY, int size);

Tft.drawRectangle(0, 0, 30,319,WHITE);

Tft.drawString(“Its HOT in here”, 15, 5, 3, RED, orientation);



Tft.drawRectangle(35, 5, 110,310,RED);

Tft.drawRectangle(36, 6, 110,310,RED);



//orientation = LANDSCAPE_UPSIDE_DOWN;

Tft.drawString(“Temperature”, 160, 40, 2, BLACK, orientation);

char tempC[5]; // Buffer big enough for 7-character float

dtostrf(tempCelcius, 4, 1, tempC); // Leave room for too large numbers!

Tft.drawString( tempC, 140, 65, 4, RED, orientation);

Tft.drawString( “O”, 120, 65, 2, BLACK, orientation);

Tft.drawString( “C”, 90, 65, 4, BLACK, orientation);





char tempF[5]; // Buffer big enough for 7-character float

dtostrf(tempFh, 4, 1, tempF); // Leave room for too large numbers!

Tft.drawString( tempF, 140, 100, 4, RED, orientation);

Tft.drawString( “O”, 120, 100, 2, BLACK, orientation);

Tft.drawString( “F”, 90, 100, 4, BLACK, orientation);

}



void draw_green_zone(float tempCelcius, float tempFh)

{

//int drawString(char *string, int poX, int poY, int size);

Tft.drawRectangle(0, 0, 30,319,WHITE);

Tft.drawString(“Its NICE in here”, 15, 5, 3, GREEN, orientation);



//Tft.drawRectangle(0, 10, 239,300,WHITE);

Tft.drawRectangle(35, 5, 110,310,GREEN);

Tft.drawRectangle(36, 6, 110,310,GREEN);



Tft.drawString(“Temperature”, 160, 40, 2, BLACK, orientation);

char tempC[5]; // Buffer big enough for 7-character float

dtostrf(tempCelcius, 3, 1, tempC); // Leave room for too large numbers!

Tft.drawString( tempC, 140, 65, 4, GREEN, orientation);

Tft.drawString( “O”, 120, 65, 2, BLACK, orientation);

Tft.drawString( “C”, 90, 65, 4, BLACK, orientation);



char tempF[5]; // Buffer big enough for 7-character float

dtostrf(tempFh, 4, 1, tempF); // Leave room for too large numbers!

Tft.drawString( tempF, 140, 100, 4, GREEN, orientation);

Tft.drawString( “O”, 120, 100, 2, BLACK, orientation);

Tft.drawString( “F”, 90, 100, 4, BLACK, orientation);

}



void draw_blue_zone(float tempCelcius, float tempFh)

{

//TextOrientation orientation;

//orientation = LANDSCAPE_UPSIDE_DOWN;

//int drawString(char *string, int poX, int poY, int size);

Tft.drawRectangle(0, 0, 30,319,WHITE);

Tft.drawString(“Its COLD in here”, 15, 5, 3, BLUE, orientation);



//Tft.drawRectangle(0, 10, 239,300,WHITE);

Tft.drawRectangle(35, 5, 110,310,BLUE);

Tft.drawRectangle(36, 6, 110,310,BLUE);



Tft.drawString(“Temperature”, 160, 40, 2, BLACK, orientation);

char tempC[5]; // Buffer big enough for 7-character float

dtostrf(tempCelcius, 3, 1, tempC); // Leave room for too large numbers!

Tft.drawString( tempC, 140, 65, 4, BLUE, orientation);

Tft.drawString( “O”, 120, 65, 2, BLACK, orientation);

Tft.drawString( “C”, 90, 65, 4, BLACK, orientation);



char tempF[5]; // Buffer big enough for 7-character float

dtostrf(tempFh, 4, 1, tempF); // Leave room for too large numbers!

Tft.drawString( tempF, 140, 100, 4, BLUE, orientation);

Tft.drawString( “O”, 120, 100, 2, BLACK, orientation);

Tft.drawString( “F”, 90, 100, 4, BLACK, orientation);

}



void draw_voltage(float voltage)

{

Tft.drawRectangle(155, 5, 65,310,BLUE);

Tft.drawRectangle(156, 6, 65,310,BLUE);



Tft.drawString(“Voltage”, 200, 160, 2, BLACK, orientation);

char voltC[5]; // Buffer big enough for 7-character float

dtostrf(voltage, 3, 1, voltC); // Leave room for too large numbers!

Tft.drawString( voltC, 140, 180, 4, BLUE, orientation);

Tft.drawString( volt, 70, 180, 3, BLACK, orientation);

}



void clear_display()

{

Tft.fillScreen(0, 240, 0, 320, WHITE);

}