回复:带有 neo 6m GPS 和按钮的 Arduino
RE: Arduino with neo 6m GPS and push button
我是航空专业的学生,刚接触编码环境。
我目前正在使用 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);
}
}```
只需将值存储在 2 个变量中即可。
#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);
}
}
我是航空专业的学生,刚接触编码环境。 我目前正在使用 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);
}
}```
只需将值存储在 2 个变量中即可。
#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);
}
}