Some time ago I wrote a usefull function for compass heading to a compass string (part of an yet unfinished library). It is quite straightforward.
char direction[17][4] = {"N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW","N"} // 68 bytes
char * degrees2direction(int degrees)
{
degrees = degrees % 360;
int idx = (degrees*10 + 112)/225;
return direction[idx];
}
As there is quite some repetition in the direction array it is possible to code the array more efficiently. E.g. "NE" is part of "NNE", etc.
The array
char s[] = "NNENESSESESSWSWNNWNW";
contains all possible directions.
Any ideas how to code this simple function more efficiently? => goal is to minimize the footprint of array AND code
TIA,