Hello everyone,
I am having some trouble with my lcd screen whenever I draw to it there is tearing on the lcd screen tearing is when part of the image from the previous frame is still displayed here is more info:http://en.wikipedia.org/wiki/Screen_tearing anyways I am wondering how to avoid tearing on the tft lcd I have looked the the SPFD5408A datasheet (I have the 1.0 screen so it uses that chip instead of the ST7781R) and it mentions vsync and high speed transfer which both would more than likely help fix my problum and I was wondering how to use those things.To show the issue I have shot a short slow motion video at 240 frames per second
mediafire.com/download.php?6uebfv2ehccj0rg
Also here is my code
#include <TFT.h>
#include <TouchScreen.h>
#define bubble_amount 20
unsigned char bubble_x[bubble_amount];
unsigned int bubble_y[bubble_amount];
unsigned char bubble_dir[bubble_amount];
unsigned char bubble_radius[bubble_amount];
inline void pushData_fast(unsigned char data);
#define RGB565(r,g,b) ((r>>3)<<11) + ((g>>2)<<5) + (b>>3)
#define RGB565_16(r,g,b) (r<<11) + (g<<5) + (b)
//Measured ADC values for (0,0) and (240-1,320-1)
//TS_MINX corresponds to ADC value when X = 0
//TS_MINY corresponds to ADC value when Y = 0
//TS_MAXX corresponds to ADC value when X = 240 -1
//TS_MAXY corresponds to ADC value when Y = 320 -1
//unsigned int red_5,green_6,blue_5;
#ifdef SEEEDUINO
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A1 // must be an analog pin, use "An" notation!
#define YM 14 // can be a digital pin, this is A0
#define XP 17 // can be a digital pin, this is A3
#endif
#ifdef MEGA
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A1 // must be an analog pin, use "An" notation!
#define YM 54 // can be a digital pin, this is A0
#define XP 57 // can be a digital pin, this is A3
#endif
//Measured ADC values for (0,0) and (210-1,320-1)
//TS_MINX corresponds to ADC value when X = 0
//TS_MINY corresponds to ADC value when Y = 0
//TS_MAXX corresponds to ADC value when X = 240 -1
//TS_MAXY corresponds to ADC value when Y = 320 -1
#define TS_MINX 140
#define TS_MAXX 900
#define TS_MINY 120
#define TS_MAXY 940
unsigned char array_fill;
#define left 1
#define right 2
#define up 3
#define down 4
#define leftdown 5
#define leftup 6
#define rightdown 7
#define rightup 8
unsigned char dir_array[]={left,right,up,down,leftdown,leftup,rightdown,rightup};
unsigned char ud_array[]={0,up,down};
unsigned char lr_array[]={0,left,right};
void fill_screen_with_color(unsigned int color)
{
Tft.setXY(0,0);
Tft.setOrientation(0);
unsigned char d1,d2;
d1=(color&0xff00)>>8;
d2=color&0xff;
for (unsigned int x_clr=0;x_clr < 38400;x_clr++)
{
CS_LOW;
RS_HIGH;
RD_HIGH;
WR_LOW;
#ifdef SEEEDUINO
PORTD &=~ 0xfc;
PORTB &=~ 0x03;
#endif
#ifdef SEEEDUINO
PORTD |= (d1<<2);
PORTB |= (d1>>6);
#endif
WR_HIGH;
WR_LOW;
#ifdef SEEEDUINO
PORTD &=~ 0xfc;
PORTB &=~ 0x03;
#endif
#ifdef SEEEDUINO
PORTD |= (d2<<2);
PORTB |= (d2>>6);
#endif
WR_HIGH;
CS_HIGH;
CS_LOW;
RS_HIGH;
RD_HIGH;
WR_LOW;
#ifdef SEEEDUINO
PORTD &=~ 0xfc;
PORTB &=~ 0x03;
#endif
#ifdef SEEEDUINO
PORTD |= (d1<<2);
PORTB |= (d1>>6);
#endif
WR_HIGH;
WR_LOW;
#ifdef SEEEDUINO
PORTD &=~ 0xfc;
PORTB &=~ 0x03;
#endif
#ifdef SEEEDUINO
PORTD |= (d2<<2);
PORTB |= (d2>>6);
#endif
WR_HIGH;
CS_HIGH;
}
}
void setup()
{
//set the screen to background color
Tft.init();//init TFT
Serial.begin(9600);
//Tft.fillRectangle(0,0,240,320,RGB565(16,40,112));
fill_screen_with_color(RGB565(16,40,112));
randomSeed(analogRead(4));
//now randomly fill in circle data
for (array_fill=0;array_fill < bubble_amount;array_fill++)
{
bubble_x[array_fill]=random(30,240);
bubble_y[array_fill]=random(30,320);
bubble_radius[array_fill]=random(15,1);
bubble_dir[array_fill]=right;//dir_array[random(8)];
}
}
/*
random syntax
random(max)
random(min, max)
// a random number from 0 to 299
random(300);
// a random number from 10 to 19
random(10, 20);
*/
void loop()
{
//start by clearing all circles
//Tft.fillRectangle(0,0,240,320,RGB565(16,40,112));
fill_screen_with_color(RGB565(16,40,112));
//now draw all the circules in a loop
for (array_fill=0;array_fill < bubble_amount;array_fill++)
{
switch (bubble_dir[array_fill])
{
case left:
// Serial.println("left bubble");
//first see if it the bubble has gone too far
if (bubble_x[array_fill] < bubble_radius[array_fill]*2)
{
//change direction to right
Serial.println("Direction changed from left to right");
bubble_dir[array_fill]=right+ud_array[random(3)];
bubble_x[array_fill]+=4;
}
else
{
bubble_x[array_fill]--;
}
break;
case right:
// Serial.println("Right bubble");
//first see if it the bubble has gone too far
if (bubble_x[array_fill] > 240-(bubble_radius[array_fill]*2))
{
//change direction to left
Serial.println("Direction changed from right to left");
bubble_dir[array_fill]=right+ud_array[random(3)];
bubble_x[array_fill]-=4;
}
else
{
bubble_x[array_fill]++;
}
break;
case up:
if (bubble_y[array_fill] < bubble_radius[array_fill]*2)
{
//change it to down
Serial.println("Direction changed from up to down");
bubble_dir[array_fill]=down+lr_array[random(3)];
bubble_y[array_fill]+=4;
}
else
{
bubble_y[array_fill]--;
}
break;
case down:
if (bubble_y[array_fill] > 320-(bubble_radius[array_fill]*2))
{
//change direction to left
Serial.println("Direction changed from down to up");
bubble_dir[array_fill]=up+lr_array[random(3)];
bubble_y[array_fill]-=4;
}
else
{
bubble_y[array_fill]++;
}
case rightdown:
if (bubble_y[array_fill] > 320-(bubble_radius[array_fill]*2))
{
//change direction to left
Serial.println("Direction changed from down to up");
bubble_dir[array_fill]=up+lr_array[random(3)];
bubble_y[array_fill]-=4;
}
else
{
bubble_y[array_fill]++;
}
if (bubble_x[array_fill] > 240-(bubble_radius[array_fill]*2))
{
//change direction to left
Serial.println("Direction changed from right to left");
bubble_dir[array_fill]=right+ud_array[random(3)];
bubble_x[array_fill]-=4;
}
else
{
bubble_x[array_fill]++;
}
break;
case rightup:
if (bubble_y[array_fill] < bubble_radius[array_fill]*2)
{
//change it to down
Serial.println("Direction changed from up to down");
bubble_dir[array_fill]=down+lr_array[random(3)];
bubble_y[array_fill]+=4;
}
else
{
bubble_y[array_fill]--;
}
if (bubble_x[array_fill] > 240-(bubble_radius[array_fill]*2))
{
//change direction to left
Serial.println("Direction changed from right to left");
bubble_dir[array_fill]=right+ud_array[random(3)];
bubble_x[array_fill]-=4;
}
else
{
bubble_x[array_fill]++;
}
break;
case leftdown:
if (bubble_y[array_fill] > 320-(bubble_radius[array_fill]*2))
{
//change direction to left
Serial.println("Direction changed from down to up");
bubble_dir[array_fill]=up+lr_array[random(3)];
bubble_y[array_fill]-=4;
}
else
{
bubble_y[array_fill]++;
}
if (bubble_x[array_fill] < bubble_radius[array_fill]*2)
{
//change direction to right
Serial.println("Direction changed from left to right");
bubble_dir[array_fill]=right+ud_array[random(3)];
bubble_x[array_fill]+=4;
}
else
{
bubble_x[array_fill]--;
}
break;
case leftup:
if (bubble_y[array_fill] < bubble_radius[array_fill]*2)
{
//change it to down
Serial.println("Direction changed from up to down");
bubble_dir[array_fill]=down+lr_array[random(3)];
bubble_y[array_fill]+=4;
}
else
{
bubble_y[array_fill]--;
}
if (bubble_x[array_fill] < bubble_radius[array_fill]*2)
{
//change direction to right
Serial.println("Direction changed from left to right");
bubble_dir[array_fill]=right+ud_array[random(3)];
bubble_x[array_fill]+=4;
}
else
{
bubble_x[array_fill]--;
}
break;
}
Tft.drawCircle(bubble_x[array_fill],bubble_y[array_fill], bubble_radius[array_fill],RGB565(240,240,255));
Tft.drawCircle(bubble_x[array_fill]-4,bubble_y[array_fill]-4, bubble_radius[array_fill]/3,RGB565(240,240,255));
}//end of for loop
}