You are on page 1of 2

struct RectPlateLocation

{
int left;
int right;
int top;
int bottom;
int IDx;
int IDy;
int digpin;
};

void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
}
void loop() {
// put your main code here, to run repeatedly:
struct RectPlateLocation plate[4];
plate[0].left=0;
plate[0].right=10;
plate[0].bottom=0;
plate[0].top=10;
plate[0].IDx=1;
plate[0].IDy=1;
plate[0].digpin=13;
//
plate[1].left=10;
plate[1].right=20;
plate[1].bottom=0;
plate[1].top=10;
plate[1].IDx=2;
plate[1].IDy=1;
plate[1].digpin=12;
//
plate[2].left=0;
plate[2].right=10;
plate[2].bottom=10;
plate[2].top=20;
plate[2].IDx=1;
plate[2].IDy=2;
plate[2].digpin=11;
//
plate[3].left=10;
plate[3].right=20;
plate[3].bottom=10;
plate[3].top=20;
plate[3].IDx=2;
plate[3].IDy=2;
plate[3].digpin=10;
////////
int currX;
int currY;
int targetX;
int targetY;
RectPlateLocation targetPlate;
for(int i=0;i<6;i++)
{
if(targetX<plate[i].right && targetX>plate[i].left && targetY<plate[i].top &&
targetY>plate[i].bottom)
{
targetPlate=plate[i];
}
}

RectPlateLocation currPlate;
for(int j=0;j<6;j++)
{
if(currX<plate[j].right && currX>plate[j].left && currY<plate[j].top && currY>
plate[j].bottom)
{
currPlate=plate[j];
}
}
int diffX = targetPlate.IDx-currPlate.IDx;
int diffY = targetPlate.IDy-currPlate.IDy;
if(diffX < 0)
{
digitalWrite(plate[currPlate.IDx-1].digpin, HIGH);
}
else if(diffX > 0)
{
digitalWrite(plate[currPlate.IDx+1].digpin, HIGH);
}
else if(diffX == 0)
{
if(diffY < 0)
{
digitalWrite(plate[currPlate.IDy-1].digpin, HIGH);
}
if(diffY > 0)
{
digitalWrite(plate[currPlate.IDy+1].digpin, HIGH);
}
}
}

You might also like