###前提・実現したいこと
Arduinoのプログラムを用いてGPSモジュールから座標を取得するプログラムについてなのですが、このままだと永遠に座標を取得し続けてしまいます。一度だけ座標を取得させるにはどのように改良すればいいのでしょうか?
###Arduino
#include "SoftwareSerial.h" #define rxPin 10 #define txPin 11 SoftwareSerial GPSSerial(rxPin, txPin); byte index; char buf[200]; char *ptr_format_id; char *ptr_utc_time; char *ptr_latitude; // S <--> N char *ptr_latitude_sn; char *ptr_longitude; // E <--> W char *ptr_longitude_ew; void clear_buf() { for( byte index = 0 ; index < 200 ; index++ ) { buf[index] = 0; } } void setup() { Serial.begin(9600); Serial.println("GPS GET location"); clear_buf(); index = 0; GPSSerial.begin(9600); } void loop() { char chr; double latitude; double longitude; if( GPSSerial.available() ) { chr = GPSSerial.read(); if( (chr == 0x0d) || (chr == 0x0a) ) { ptr_format_id = strtok( buf, "," ); if( strncmp( ptr_format_id, "$GPGGA", 6 ) == 0 ) { ptr_utc_time = strtok( NULL, "," ); ptr_latitude = strtok( NULL, "," ); ptr_latitude_sn = strtok( NULL, "," ); ptr_longitude = strtok( NULL, "," ); ptr_longitude_ew = strtok( NULL, "," ); latitude = atoi( ptr_latitude ) / 100; latitude += (atof(ptr_latitude) - latitude * 100) / 60; longitude = atoi( ptr_longitude ) / 100; longitude += (atof(ptr_longitude) - longitude * 100) / 60; //Serial.print(ptr_latitude_sn); Serial.print(latitude,8); Serial.print(","); //Serial.print(ptr_longitude_ew); Serial.print(longitude,8); Serial.println(""); } clear_buf(); index = 0; } else { buf[index] = chr; index++; } } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/17 07:33