Hello all,

I have a question with regard to the code below. What I am trying to do is this -

1. draw an arrow with the given co-ordinates and angle,

2. increment angle in the main for loop,

3. erase the old arrow if the angke has changed and then sraw the new one.

however, this code seems to work only for the first two times. for example, if I set i = 0 and increment by 5, the erase IF works only for 0 and 5. All other values of i seem to ignore the IF condition.

Any help with this would be greatly appreciated.

Thank you,

Madhu.

#include <T6963.h>

T6963 lcd(240, 128, 6, 32);

int x0, y0, arrowHeight, arrowWidth, i;

void setup()

{

Serial.begin(9600);

lcd.Initialize();

lcd.clearGraphic();

}

void loop()

{

for(i = 0; i <= 360; i += 5)

{

createArrow(118, 64, 60, 20, i);

delay(30000);

}

}

void createArrow(int x0, int y0, int arrowHeight, int arrowWidth, int angle)

{

int x1, x2, y1, y2, x3, y3;

int x0_old;

int x1_old;

int x2_old;

int x3_old;

int y0_old;

int y1_old;

int y2_old;

int y3_old;

int old_angle = 0;

x1 = x0 + arrowWidth;

y1 = y0;

x2 = x0 + (arrowWidth / 2);

y2 = abs(y0 - arrowHeight);

x3 = x2;

y3 = y0 - 10;

x0_old = x0;

x1_old = x1;

x2_old = x2;

x3_old = x3;

y0_old = y0;

y1_old = y1;

y2_old = y2;

y3_old = y3;

if((angle - old_angle) > 0)

{

old_angle = angle;

lcd.createLine(x1_old, y1_old, x2_old, y2_old, 0);

lcd.createLine(x0_old, y0_old, x2_old, y2_old, 0);

lcd.createLine(x0_old, y0_old, x3_old, y3_old, 0);

lcd.createLine(x1_old, y1_old, x3_old, y3_old, 0);

}

Serial.print(angle, DEC);

Serial.print(" ");

Serial.println(old_angle, DEC);

float theta = angle*(3.1415/180);

int cx_x0, cy_y0, cx_x1, cy_y1, cx_x2, cy_y2, cx_x3, cy_y3;

int x_ref = ((x0 + x1 + x2)/3);

int y_ref = ((y0 + y1 + y2)/3);

cx_x0 = x0 - x_ref;

cy_y0 = y0 - y_ref;

cx_x1 = x1 - x_ref;

cy_y1 = y1 - y_ref;

cx_x2 = x2 - x_ref;

cy_y2 = y2 - y_ref;

cx_x3 = x3 - x_ref;

cy_y3 = y3 - y_ref;

x0= x_ref - ((int)(cx_x0*cos(theta)))-((int)(cy_y0* sin(theta)));

y0= y_ref - ((int)(cx_x0*sin(theta)))+((int)(cy_y0* cos(theta)));

x1= x_ref - ((int)(cx_x1*cos(theta)))-((int)(cy_y1* sin(theta)));

y1= y_ref - ((int)(cx_x1*sin(theta)))+((int)(cy_y1* cos(theta)));

x2= x_ref - ((int)(cx_x2*cos(theta)))-((int)(cy_y2* sin(theta)));

y2= y_ref - ((int)(cx_x2*sin(theta)))+((int)(cy_y2* cos(theta)));

x3= x_ref - ((int)(cx_x3*cos(theta)))-((int)(cy_y3* sin(theta)));

y3= y_ref - ((int)(cx_x3*sin(theta)))+((int)(cy_y3* cos(theta)));

lcd.createLine(x1, y1, x2, y2, 1);

lcd.createLine(x0, y0, x2, y2, 1);

lcd.createLine(x0, y0, x3, y3, 1);

lcd.createLine(x1, y1, x3, y3, 1);

}