[media = x,1280,720] http://v.youku.com/v_show/id_XMzk0NjQ4NTgyOA==.html?spm=a2h3j.8428770.3416059.1 [/ media]源码:
#include <LCD5110_Basic.h>
#include < TinyGPS ++。h>
#include <SoftwareSerial.h>
LCD5110 myGLCD(3,4,5,7,6);
static const int RXPin = 12,TXPin = 11;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin,TXPin);
extern uint8_t SmallFont [];
extern uint8_t MediumNumbers [];
extern uint8_t BigNumbers [];
void BP(){
myGLCD.print(“Please wait”,0,0);
myGLCD.print(“连接GPS”,0,9);
}
wait wait(){
delay(500);
myGLCD.print(,0,17 “”);
延迟(500);
myGLCD.print( “..”,0,17);
延迟(500);
myGLCD.print( “...”,0,17);
延迟(500);
myGLCD.print( “....”,0,17);
延迟(500);
myGLCD.print( “.....”,0,17);
延迟(500);
myGLCD.print( “......”,0,17);
延迟(500);
}
void setup(){
myGLCD.InitLCD(); //初始化LCD
myGLCD.setFont(SmallFont);
myGLCD.setContrast(70);
延迟(100);
Serial.begin(9600);
ss.begin(GPSBaud);
BP();
等待();
}
void loop(){
//每次正确编码新句子时,此草图都会显示信息。
而(ss。
gps.encode(ss.read());
if(gps.location.isUpdated()){
//纬度(度)(double)
Serial.print(“Latitude =”);
Serial.print(gps.location.lat(),6);
//以度为单位的经度(double)
Serial.print(“Longitude =”);
Serial.println(gps.location.lng(),6);
//原始纬度全度
Serial.print(“Raw latitude =”);
Serial.print(gps.location.rawLat()。negative?“ - ”:“+”);
Serial.println(gps.location.rawLat()度);
// ...和十亿分之一(u16 /
u32 )Serial.println(gps.location.rawLat()。billionths);
//整经度的原始经度
Serial.print(“Raw longitude =”);
Serial.print(gps.location.rawLng()。negative?“ - ”:“+”);
Serial.println(gps.location.rawLng()度);
// ...和十亿分之一(u16 /
u32 )Serial.println(gps.location.rawLng()。billionths);
// DDMMYY格式的原始日期(u32)
Serial.print(“Raw date DDMMYY =”);
Serial.println(gps.date.value());
//年(2000+)(u16)
Serial.print(“Year =”);
Serial.println(gps.date.year());
//月(1-12)(u8)
Serial.print(“Month =”);
Serial.println(gps.date.month());
// Day(1-31)(u8)
Serial.print(“Day =”);
Serial.println(gps.date.day());
int day = gps.date.day();
// HHMMSSCC格式的原始时间(u32)
Serial.print(“HHMMSSCC中的原始时间=”);
Serial.println(gps.time.value());
//小时(0-23)(u8)
Serial.print(“Hour =”);
Serial.println(gps.time.hour());
int hour = gps.time.hour();
if(hour> = 16){day ++;}
hour + = 8;
if(hour == 24){hour - = 24;}
// Minute(0-59)(u8)
Serial.print(“Minute =”);
Serial.println(gps.time.minute());
//秒(0-59)(u8)
Serial.print(“Second =”);
Serial.println(gps.time.second());
// 100秒(0-99)(u8)
Serial.print(“Centisecond =”);
Serial.println(gps.time.centisecond());
//原始速度为100的结(i32)
Serial.print(“原始速度为100th / knot =”);
Serial.println(gps.speed.value());
//速度(双)
Serial.print(“速度以节/ h =”);
Serial.println(gps.speed.knots());
//以英里/小时为单位的速度(双倍)
Serial.print(“以英里为单位的速度/ h =”);
Serial.println(gps.speed.mph());
//以秒为单位的速度(双倍)
Serial.print(“以m / s为单位的速度=”);
Serial.println(gps.speed.mps());
//以每小时公里为单位的速度(双倍)
Serial.print(“以km / h为单位的速度=”);
Serial.println(gps.speed.kmph());
// 100度的原始课程(i32)
Serial.print(“Raw course in degrees =”);
Serial.println(gps.course.value());
//以度为单位的课程(双人)
Serial.print(“Course in degrees =”);
Serial.println(gps.course.deg());
//以厘米为单位的原始高度(i32)
Serial.print(“以厘米为单位的原始高度=”);
Serial.println(gps.altitude.value());
//海拔高度(米)(双倍)
Serial.print(“海拔高度米=”);
Serial.println(gps.altitude。
//海拔高度(英里)(双倍)
Serial.print(“Altitude in miles =”);
Serial.println(gps.altitude.miles());
//海拔高度(公里)(双倍)
Serial.print(“海拔高度公里=”);
Serial.println(gps.altitude.kilometers());
//海拔高度(双倍)
Serial.print(“海拔高度=英尺=”);
Serial.println(gps.altitude.feet());
//正在使用的卫星数量(
u32 )Serial.print(“正在使用的数量os卫星=”);
Serial.println(gps.satellites.value());
//水平暗淡 of Precision(100ths-i32)
Serial.print(“HDOP =”);
Serial.println(gps.hdop.value());
myGLCD.setFont(SmallFont);
myGLCD.clrScr(); //清屏
myGLCD.printNumI(gps.date.year(),0,0);
myGLCD.printNumI(gps.date.month(),35,0);
myGLCD.printNumI(日,64,0);
myGLCD.printNumI(小时,0,12);
myGLCD.print( “:”,13,12);
myGLCD.printNumI(gps.time.minute(),25,12);
myGLCD.print( “:”,37,12);
myGLCD.printNumI(gps.time.second(),49,12);
myGLCD.printNumF(gps.location.lat(),6,0,32);
myGLCD.printNumF(gps.location.lng(),6,0,40);
/ *
显示时间格式: 年月
日
时分秒
* /
myGLCD.printNumI(gps.satellites.value(),72,21); //显示正在使用的卫星数量。
myGLCD.print( “公里/小时”,60,24);
myGLCD.setFont(MediumNumbers); //速度字体调大
.myGLCD.printNumF(gps.speed.kmph(),2,0,16); //显示速度。(km / h)
delay(100);
}
}
}
|