回复:Arduino带有neo 6m GPS和按钮



我是一名航空专业的学生,刚接触编码环境。我目前正在使用Arduino mega 2560开发一个GPS neo 6m模块,我想在按下按钮后保存当前位置。按下按钮可使用哪个功能保存位置。以下是我迄今为止所做的工作。任何帮助都将不胜感激。提前谢谢。

#include <SoftwareSerial.h>
// The TinyGPS++ object
TinyGPSPlus gps;
static const int RXPin = 4, TXPin = 3; //gps module connections
static const uint32_t GPSBaud = 9600;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
const int PUSH_BUTTON = 2;
void setup(){
pinMode(PUSH_BUTTON, INPUT_PULLUP); //push button input

Serial.begin(9600);
ss.begin(GPSBaud);
} 
void loop(){
unsigned char i;
static const double homeLat = 12.334455, homeLon = 05.112233;

while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= "); 
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= "); 
Serial.println(gps.location.lng(), 6);
}

status = digitalRead(PUSH_BUTTON);
if (status== HIGH){
*missing code/confused*
}  

delay(1000);
}
}```

只需将值存储在两个变量中即可。

#include <SoftwareSerial.h>
// The TinyGPS++ object
TinyGPSPlus gps;
static const int RXPin = 4, TXPin = 3; //gps module connections
static const uint32_t GPSBaud = 9600;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

const int PUSH_BUTTON = 2;
double save_lat, save_lang;
void setup(){
pinMode(PUSH_BUTTON, INPUT_PULLUP); //push button input

Serial.begin(9600);
ss.begin(GPSBaud);
} 

void loop(){
unsigned char i;
static const double homeLat = 12.334455, homeLon = 05.112233;


while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= "); 
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= "); 
Serial.println(gps.location.lng(), 6);
}


status = digitalRead(PUSH_BUTTON);
if (status== HIGH){
if (gps.location.isUpdated()){
save_lat = gps.location.lat();
save_lang = gps.location.lng();
}  
}
delay(1000);
}
}

最新更新