Pages: [1]   Go Down
Author Topic: Flip/mirror a TFT LCD screen  (Read 159 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino Uno
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, long-time reader, first-time poster smiley

I've bought the Arduino 1.8" TFT LCD screen (http://arduino.cc/en/Main/GTFT) and am looking to develop a small HUD device for use in a car, to be reflected onto the windscreen by placing my unit on the dashboard beneath it. It's somewhat inspired by the Garmin HUD:


My current stumbling point is that the libraries do not have a built-in function that would flip/mirror the display in the same way that Processing offers the mirror function. I need to be able to flip the y-axis over so it can be read properly by the user.

I've had a good search across the internet and on the forum, and have found several people making HUDs or having problems where they initially have a flipped screen. The closest I've come to fixing it myself is this topic: http://forum.arduino.cc/index.php?topic=215574.0, where the OP has started with a flipped screen, but then called a map to invert the axis to solve it for him. I have tried to do this myself byt haven't had much luck. I've looked into the adafruit gfx and st7735 libraries that the tft library is based on and can't find any functions to call on.

Here is the code I'm working with to try to flip the screen. It's just a counter at the moment as a timely reminder of how long I've been searching for a solution  smiley-razz The map part is in the setup area.

Code:
#include <TFT.h> // Hardware-specific library
#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library

#define CS   10
#define DC   9
#define RESET  8 

// pin definition for the Leonardo
// #define CS   7
// #define DC   0
// #define RESET  1

TFT myScreen = TFT(CS, DC, RESET);

// variable to keep track of the elapsed time
unsigned long seconds = 0;
unsigned long newseconds = 0;
unsigned long minutes = 0;
unsigned long width = 160;
unsigned long height = 128;
// char array to print time
char printout[4];
char printout2[4];

void setup() {
    myScreen.begin(); 


//This is my test bed for trying to map a flip but failing miserably

   myScreen.width()= map(myScreen.width(),0,159,159,0);
   myScreen.height()= map(myScreen.height(),0,127,127,0);

//I'm aware this doesn't compile, I've tried a few things that don't work


  myScreen.background(0,0,0); // clear the screen
  myScreen.stroke(255,0,255);
  // static text
    myScreen.setTextSize(2);
  myScreen.text("Running for",0,0);
  myScreen.text("minutes",0,50);
 myScreen.text("seconds",0,100);
  // increase font size for text in loop()
  myScreen.setTextSize(4);
}




void loop() {
     // get elapsed time
    seconds = millis();
    newseconds = (seconds - (minutes*60000));
    if (newseconds > 59999) {
      minutes++;
     
    }
    // convert to a string
    String elapsedMins = String(minutes);
    String elapsedSecs = String(newseconds/1000);
    // add to an array
    elapsedMins.toCharArray(printout2,4);
    elapsedSecs.toCharArray(printout,4);
    // print out and erase
    myScreen.stroke(255,255,255);
    myScreen.text(printout2,0,20);
    myScreen.text(printout,0,70);
    delay(1000);
    myScreen.stroke(0,0,0);
    myScreen.text(printout2,0,20);
    myScreen.text(printout,0,70);

}

Does anyone have any pointers as to where to go with this? Is mapping a good way about it?

Or is it something that could be written into the library?

Thanks for reading!
Logged

Pages: [1]   Go Up
Jump to: