Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen alignment #6

Open
BorisFR opened this issue Apr 16, 2018 · 2 comments
Open

Screen alignment #6

BorisFR opened this issue Apr 16, 2018 · 2 comments

Comments

@BorisFR
Copy link

BorisFR commented Apr 16, 2018

I'm using the adafruit lib like this:
`#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#define TFT_RST -1
#define TFT_SCLK 5
#define TFT_CS 16
#define TFT_DC 17
#define TFT_MOSI 23
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

void box (uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color) {
for(uint8_t i=x; i<(x+width); i++)
for(uint8_t j=y;j<(y+height);j++)
tft.drawPixel(i, j, color);
}

void setup() {
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_BLACK);
box(0,0,17,17,ST7735_CYAN);
box(1,1,15,15,ST7735_RED);
box(2,2,13,13,ST7735_WHITE);
box(3,3,11,11,ST7735_BLUE);
}
`
Display on the left start with white (missing cyan and red), and on top with red (missing cyan). And there is also garbage on the screen at right and bottom as fillscreen ... don't fill the screen.

Do you have the same problem?

@BorisFR
Copy link
Author

BorisFR commented Apr 19, 2018

In fact, I found the lib TFT_eSPI by Bodmer and it is THE lib to use!
https://github.com/Bodmer/TFT_eSPI
The config to put in "User_Setup.h"

#define ST7735_DRIVER
#define TFT_WIDTH 128
#define TFT_HEIGHT 160
#define ST7735_GREENTAB2
#define TFT_CS 16
#define TFT_DC 17
#define TFT_RST -1
#define TFT_MISO -1
#define TFT_MOSI 23
#define TFT_SCLK 5
//#define SMOOTH_FONT

And then, it is just work great and really fast!

@jvhaarst
Copy link

jvhaarst commented Jun 2, 2018

This is about 10 times faster than the example the board came with :

#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>

TFT_eSPI tft = TFT_eSPI();       // Invoke custom library

float r, x1, ya, z1, x2, y2, z2, x3, y3, z3;               //
int f[8][2], x, y;                                         // Draw box, x, y center
int c[8][3] = {                                            // Cube
 {-20,-20, 20},{20,-20, 20},{20,20, 20},{-20,20, 20},
 {-20,-20,-20},{20,-20,-20},{20,20,-20},{-20,20,-20} };
//uint32_t fstart = 0;  // start time for frame rate calculation
//uint32_t fend = 0;    // end time for frame rate calculation
//float fps = 0;        // Used in frame rate calculation

void setup(void) {
  //Serial.begin(115200);
  tft.init(); 
  tft.fillScreen(TFT_BLACK);                                // CLEAR
  tft.setTextColor(TFT_GREEN);                             
  tft.setRotation(1);                                      // 
  x = tft.width() /2; x = x + 14;                          // x Center Calculate
  y = tft.height()/2;                                      // y Center Calculate
}
 
void loop(){
 for (int a = 0; a <= 360; a = a + 2 ) {                   // 0 to 360 degree
   for (int i = 0; i < 8; i++) {                           //
    r  = a * 0.0174532;                                    // 1 degree
    x1 = c[i][2] * sin(r) + c[i][0] * cos(r);              // rotate Y
    ya = c[i][1];                                          //
    z1 = c[i][2] * cos(r) - c[i][0] * sin(r);              //
    x2 = x1;                                               //
    y2 = ya * cos(r) - z1 * sin(r);                        // rotate X
    z2 = ya * sin(r) + z1 * cos(r);                        //
    x3 = x2 * cos(r) - y2 * sin(r);                        // rotate Z
    y3 = x2 * sin(r) + y2 * cos(r);                        //
    z3 = z2; x3 = x3 + x ; y3 = y3 + y ;                   //
    f[i][0] = x3; f[i][1] = y3; f[i][2] = z3;              // store new values
   }
   //fstart = millis();
   tft.fillScreen(TFT_BLACK);
   tft.drawLine(f[0][0],f[0][1],f[1][0],f[1][1],TFT_WHITE);
   tft.drawLine(f[1][0],f[1][1],f[2][0],f[2][1],TFT_WHITE);
   tft.drawLine(f[2][0],f[2][1],f[3][0],f[3][1],TFT_WHITE);
   tft.drawLine(f[3][0],f[3][1],f[0][0],f[0][1],TFT_WHITE);
   tft.drawLine(f[4][0],f[4][1],f[5][0],f[5][1],TFT_WHITE);
   tft.drawLine(f[5][0],f[5][1],f[6][0],f[6][1],TFT_WHITE);
   tft.drawLine(f[6][0],f[6][1],f[7][0],f[7][1],TFT_WHITE);
   tft.drawLine(f[7][0],f[7][1],f[4][0],f[4][1],TFT_WHITE);
   tft.drawLine(f[0][0],f[0][1],f[4][0],f[4][1],TFT_WHITE);
   tft.drawLine(f[1][0],f[1][1],f[5][0],f[5][1],TFT_WHITE);
   tft.drawLine(f[2][0],f[2][1],f[6][0],f[6][1],TFT_WHITE);
   tft.drawLine(f[3][0],f[3][1],f[7][0],f[7][1],TFT_WHITE);
   tft.drawLine(f[1][0],f[1][1],f[3][0],f[3][1],TFT_WHITE);// cross
   tft.drawLine(f[0][0],f[0][1],f[2][0],f[2][1],TFT_WHITE);// cross
   //fend = millis();
   //fps = (1000) / (fend-fstart);
   //tft.drawFloat(fps, 0, 0, 2);
   //Serial.print(fps); Serial.println("fps");// Show frame rate
   //delay(5);
 }
}

(on my board, the fps is about 60)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants