Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TM1637.h>
- int CLK = 6;
- int DIO = 5;
- TM1637 tm(CLK, DIO);
- #include <EEPROM.h>
- float distanceToDest[10];
- float courseToDest[10];
- byte a = 22;
- int posto = 0;
- float piu_vicino = 999923.54;
- struct LatLon
- {
- float Lat;
- float Lon;
- };
- struct LatLon LatLonList[] =
- {
- {38.210169, -75.689734},
- {38.210169, -75.689734}, // United Arab Emirates
- {45.383860, 9.2839777}, // mio44
- {41.153332, 20.168331}, // Albania
- {41.153332, 20.168331}, // Armenia
- {43.153332, 24.168331}, // Armenia
- };
- int LatLonCount = sizeof LatLonList / sizeof LatLonList[0];
- byte Index = 0;
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- static const int RXPin = 4, TXPin = 3;
- static const uint32_t GPSBaud = 9600;
- // The TinyGPS++ object
- TinyGPSPlus gps;
- // The serial connection to the GPS device
- SoftwareSerial ss(RXPin, TXPin);
- // For stats that happen every 5 seconds
- unsigned long last = 0UL;
- int ledPin = 13;
- void writeCoords() {
- int address = 0;
- for (int i = 0; i < LatLonCount; i++) {
- EEPROM.put(address, LatLonList[i].Lat);
- address += sizeof(LatLonList[i].Lat);
- EEPROM.put(address, LatLonList[i].Lon);
- address += sizeof(LatLonList[i].Lon);
- }
- }
- void readCoords() {
- int address = 0;
- for (int i = 0; i < LatLonCount; i++) {
- EEPROM.get(address, LatLonList[i].Lat);
- address += sizeof(LatLonList[i].Lat);
- EEPROM.get(address, LatLonList[i].Lon);
- address += sizeof(LatLonList[i].Lon);
- }
- }
- void setup() {
- Serial.begin(9600);
- ss.begin(GPSBaud);
- pinMode(ledPin, OUTPUT);
- pinMode(7, INPUT_PULLUP);
- pinMode(8, INPUT_PULLUP);
- pinMode(9, INPUT_PULLUP);
- }
- void loop() {
- //simulo il tasto ma va fatta nel setup
- if (digitalRead(7) == LOW) {
- Serial.print(F(" leggi leggi "));
- readCoords();
- }
- if (digitalRead(8) == LOW) {
- Serial.print(F(" scrivi nuova posizione posiznione n:"));
- writeCoords();
- }
- if (digitalRead(9) == LOW) {
- Serial.print(F(" cancella tutte le posizioni"));
- }
- float currentLat, currentLon;
- // Dispatch incoming characters
- while (ss.available() > 0) {
- gps.encode(ss.read());
- }
- if (gps.location.isUpdated() && millis() - last > 5000)
- {
- last = millis();
- currentLat = gps.location.lat();
- currentLon = gps.location.lng();
- Serial.print(F(" Lat="));
- Serial.print(currentLat, 6);
- Serial.print(F(" Long="));
- Serial.println(currentLon, 6);
- Serial.print(F(" course="));
- Serial.println(gps.course.deg());
- if (gps.location.isValid())
- {
- Serial.println("Fix is valid.");
- }
- else
- {
- Serial.println("Fix is not yet valid.");
- return;
- }
- for (int x = 0; x < LatLonCount; x++) {
- distanceToDest[x] =
- TinyGPSPlus::distanceBetween(
- currentLat,
- currentLon,
- LatLonList[x].Lat,
- LatLonList[x].Lon);
- courseToDest[x] =
- TinyGPSPlus::courseTo(
- currentLat,
- currentLon,
- LatLonList[x].Lat,
- LatLonList[x].Lon);
- Serial.print(F("Distance:"));
- Serial.print(x); Serial.print(" Km ");
- Serial.print(distanceToDest[x] / 1000, 3); // *Prints distance to destination
- Serial.print(" angolazione : ");
- Serial.print(courseToDest[x]);
- Serial.println(F(" gradi"));
- Serial.print(F("direzione cardinale ["));
- Serial.print(TinyGPSPlus::cardinal(courseToDest[x]));
- Serial.println(F("]"));
- if (distanceToDest[x] < piu_vicino) {//creo valore
- posto = x; // point
- piu_vicino = distanceToDest[x] / 1000; //+ vicino
- }
- if (distanceToDest[x] / 1000 < 6.0500) { //
- a = x; // imposto soglia limite distanza
- }
- }
- Serial.print(piu_vicino);
- Serial.print(F(" Km piu' vicino ")); Serial.println(posto);
- if (a < 7) {
- Serial.print("We have arrived.");
- Serial.println(a);
- digitalWrite(ledPin, HIGH);
- Index++;
- //delay(1500);
- if (Index >= LatLonCount)
- Index = 0; // Start over when we run out of destinations
- // EEPROM.put(0, Index);
- a = 8;
- }
- else
- {
- digitalWrite(ledPin, LOW);
- a = 8;
- //delay(1500);
- }
- }
- if (gps.charsProcessed() < 10)
- Serial.println(F("WARNING: No GPS data. Check wiring."));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement