From 34009781567716c26b67a53cb70e2ce3e17357a3 Mon Sep 17 00:00:00 2001 From: JD Date: Sun, 14 Feb 2016 08:51:43 -0600 Subject: [PATCH] update LCD GPS sketch --- .../LCD_gps__tmp.ino | 0 LCD_gps_plus_tmp/LCD_gps_plus_tmp.ino | 71 +++++++++++++++++++ LCD_gps_tmp/LCD_gps_tmp.ino | 67 +++++++++++++++++ 3 files changed, 138 insertions(+) rename LCD_gps_tmp.ino => LCD_gps__tmp/LCD_gps__tmp.ino (100%) create mode 100644 LCD_gps_plus_tmp/LCD_gps_plus_tmp.ino create mode 100644 LCD_gps_tmp/LCD_gps_tmp.ino diff --git a/LCD_gps_tmp.ino b/LCD_gps__tmp/LCD_gps__tmp.ino similarity index 100% rename from LCD_gps_tmp.ino rename to LCD_gps__tmp/LCD_gps__tmp.ino diff --git a/LCD_gps_plus_tmp/LCD_gps_plus_tmp.ino b/LCD_gps_plus_tmp/LCD_gps_plus_tmp.ino new file mode 100644 index 0000000..b53d0d2 --- /dev/null +++ b/LCD_gps_plus_tmp/LCD_gps_plus_tmp.ino @@ -0,0 +1,71 @@ +#include +#include +#include "TinyGPS++.h" + +TinyGPSPlus gps; +SoftwareSerial ss(9, 10); + +LiquidCrystal lcd(2, 4, 5, 6, 7, 8); + +float voltage; +float tempC; +float tempF; +int potVal = 0; + +void setup() +{ + Serial.begin(115200); + ss.begin(9600); + lcd.begin(16, 2); +} + +void loop(){ + checkPot(); + if (potVal > 512){ + checkTemp(); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Temp: "); + lcd.print(tempF); + delay(1000); + } + else { + while (ss.available() > 0){ + gps.encode(ss.read()); + } + if (gps.altitude.isUpdated()){ + Serial.println(gps.location.lat(), 6); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Lat: "); + lcd.print(gps.location.lat(), 6); + lcd.setCursor(0, 1); + lcd.print("Lng: "); + lcd.print(gps.location.lng(), 6); + } + delay(500); + } +} + +static void smartdelay(unsigned long ms) +{ + unsigned long start = millis(); + do + { + while (ss.available()) + gps.encode(ss.read()); + } + while (millis() - start < ms); +} + +void checkTemp(){ + voltage = analogRead(3) * 5.0; + voltage /= 1024.0; + tempC = (voltage - 0.5) * 100; + tempF = (tempC * 9.0 / 5.0) + 32.0; +} + +void checkPot(){ + potVal = analogRead(2); +} + diff --git a/LCD_gps_tmp/LCD_gps_tmp.ino b/LCD_gps_tmp/LCD_gps_tmp.ino new file mode 100644 index 0000000..fe8aee7 --- /dev/null +++ b/LCD_gps_tmp/LCD_gps_tmp.ino @@ -0,0 +1,67 @@ +#include +#include +#include + +TinyGPS gps; +SoftwareSerial ss(9, 10); + +LiquidCrystal lcd(2, 4, 5, 6, 7, 8); + +float voltage; +float tempC; +float tempF; +int potVal = 0; + +void setup() +{ + Serial.begin(115200); + ss.begin(9600); + lcd.begin(16, 2); +} + +void loop(){ + checkPot(); + if (potVal > 512){ + checkTemp(); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Temp: "); + lcd.print(tempF); + delay(1000); + } + else { + float flat, flon; + gps.f_get_position(&flat, &flon); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Lat: "); + lcd.print(flat); + lcd.setCursor(0, 1); + lcd.print("Lng: "); + lcd.print(flon); + smartdelay(1000); + } +} + +static void smartdelay(unsigned long ms) +{ + unsigned long start = millis(); + do + { + while (ss.available()) + gps.encode(ss.read()); + } + while (millis() - start < ms); +} + +void checkTemp(){ + voltage = analogRead(3) * 5.0; + voltage /= 1024.0; + tempC = (voltage - 0.5) * 100; + tempF = (tempC * 9.0 / 5.0) + 32.0; +} + +void checkPot(){ + potVal = analogRead(2); +} +