2.8'' TFT Touch Shield drawLine bug?

Should drawLine work between any two points on the screen?

I am having problems with the drawLine function in the Arduino 1.0 library.

For example:
Tft.drawLine(25,74,72,13,RED) draws a horizontal line instead of an angled one.
Tft.drawLine(57,68,37,38,RED) causes the program to freeze with a single pixel set.

I am new to Arduino so I may be doing something wrong. Any help is appreciated.

Thanks.

Hi there,
I have tested your code ,have the same problem as you. It is indeed a BUG , and I have talked to our engineer to solve this problem.We will update the wiki soon. :slight_smile:

Regars,
Deray

here is the correct line code:

int w = x1 - x0 ;
int h = y1 - y0 ;
int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0 ;
if (w<0) dx1 = -1 ; else if (w>0) dx1 = 1 ;
if (h<0) dy1 = -1 ; else if (h>0) dy1 = 1 ;
if (w<0) dx2 = -1 ; else if (w>0) dx2 = 1 ;
int longest = abs(w) ;
int shortest = abs(h) ;
if (!(longest>shortest)) {
longest = abs(h) ;
shortest = abs(w) ;
if (h<0) dy2 = -1 ; else if (h>0) dy2 = 1 ;
dx2 = 0 ;
}
int numerator = longest >> 1 ;
for (int i=0;i<=longest;i++) {
setPixel(x0,y0,color) ;
numerator += shortest ;
if (!(numerator<longest)) {
numerator -= longest ;
x0 += dx1 ;
y0 += dy1 ;
} else {
x0 += dx2 ;
y0 += dy2 ;
}
}

Thank you for your reply,Nogueira.We have fixed the bugs of the green color display and draw line function.
The update libraries for TFT shield here.

Best regards,Frankie