Simple arrow using greater or less than relative to bearing via GPS puck

Morning,

idea behind this is for a simple 4 option arrow to point to the degrees relative to (incomingArr) which is giving a value of 0 to 360 to a home bearing point via Tinygps++

arrow to point North when the value is between 270 and 360 or 0 to 45

arrow to point East when the value is 45 to 135

arrow to point South when the value is 135 to 225

arrow to point West when the value is 225 to 315

been playing with greater but less than with a %% between but i get everything showing up or nothing....

``````
if (incomingArr > 315  )  {ttgo->tft->   fillTriangle(165,70,225,70,195,10, TFT_GREEN)} //NORTH

if (incomingArr > 45  )ttgo->tft->   fillTriangle(165,70,165,30,225,50, TFT_RED) ; //EAST

if (incomingArr > 135 )ttgo->tft->   fillTriangle(165,30,225,30,195,90, TFT_RED) ;//SOUTH

if (incomingArr > 225  )ttgo->tft->   fillTriangle(225,30,225,70,165,50, TFT_GREEN) ;//WEST
``````

Well you might get that, 316 is;

``````> 45
> 135
> 225
> 315
``````

Always best to post all your code, problems are often in the bit you dont post.

Also bear in mind that the course over ground that a GPS provides depends on movement, and at slow, say walking pace, can vary significantly as the position fix varies.

I don't think all the code would fit

Thanks for taking the time to respond, the issue with using greater or less than is that the other lines are also displayed, the idea is only one arrow is presented when between a certain value..

The GPS point is set via a home point and bearing is relative back to that, and is equated on the travel direction so no mater the long and lat as long as your traveling towards the home point the up arrow will be displayed

Found the solution so posting for any one whos is trying to create an arrow based on degrees or value...

``````
if(incomingArr >= 315.75 || incomingArr < 11.25){ ttgo->tft->     fillTriangle(165,70,225,70,195,10, TFT_GREEN) ;} //NORTH

if(incomingArr >= 45.00 && incomingArr < 135.00) { ttgo->tft->    fillTriangle(165,70,165,30,225,50, TFT_RED)  ;  }//EAST

if(incomingArr >= 136.00 && incomingArr < 225.00) { ttgo->tft->    fillTriangle(165,30,225,30,195,90, TFT_RED) ;  }//SOUTH

if(incomingArr >= 226.00 && incomingArr < 315.00) { ttgo->tft->    fillTriangle(225,30,225,70,165,50, TFT_GREEN);  }//WEST
``````

There we go, and that would have been clear if you posted all the code.

noted

You don't have to test both sides of every range. This has the advantage that you can't miss any values or have any values in two different ranges.

`````` if (incomingArr >= 315.75)
{
ttgo->tft->fillTriangle(165, 70, 225, 70, 195, 10, TFT_GREEN); //NORTH
}
else if (incomingArr >= 226.00)
{
ttgo->tft->fillTriangle(225, 30, 225, 70, 165, 50, TFT_GREEN);   //WEST
}
else if (incomingArr >= 136.00)
{
ttgo->tft->fillTriangle(165, 30, 225, 30, 195, 90, TFT_RED);   //SOUTH
}
else if (incomingArr >= 45.00)
{
ttgo->tft->fillTriangle(165, 70, 165, 30, 225, 50, TFT_RED);   //EAST
}
else // < 45.00
{
ttgo->tft->fillTriangle(165, 70, 225, 70, 195, 10, TFT_GREEN); //NORTH
}
``````

Hey @johnwasser thank you for taking the time to edit the code...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.