The general operation is of the app is that there is a list of 175 coordinates in an array (wayPt). With each cycle, the app uses TinyGPS to return a lat/long. That lat long is run through getClosestPt (which calculates the min distance to all points to get the closets distance). The function returns the closest distance and it is used (at the moment) to beep the piezo based on distance (in meters). The idea being, as you get closer to a point, the tone of the beep gets higher along with the beep count. A GPS locator of sorts. I am also using the OLED to render a few graphics and intend to do some things with the Lat/Long points (if I can figure this out). There are 3 graphics arrays (removed from the code below due to restrictions).
The issue I am having is that the app crashes after a number of cycles (seconds up to a minute or two). I think that I am wasting memory (or processing too much) but am not sure where. The OLED bits are commented out right now (in the main loop). When I turn them on, the app runs, then stops after a few seconds. I don’t think it is the OLED bits, but rather the function call I have (minDist = getClosestPt(flat, flon) that seems to bog down the processing and if I add in any more features (eg OLED), it craps out.
A few questions:
I want to store a list of GPS coordinates - is the 2D float array I have (wayPt) being dealt with in the best way? Is there a better way?
I think my getClosestPt function (and the HaverSine formula) are bogging the controller down. It is processing 175 points through these calculations every second. I can’t think of a better way to do what I want. I considered trying to weed out points in getClosestPt() by comparing them to the reference point being fed to the function and ignoring those where lat1-lat2 && lon1 - lon2 distances where greater than some value, but figured that would waste just as many resources than just throwing them all at the HaverSine formula.
any other tips welcome.
Sketch.pde is attached. (code dump was too large)
sketch.pde (19.4 KB)