【发布时间】:2013-11-10 11:12:04
【问题描述】:
提前抱歉,我觉得这将是一个非常简单的问题,但我已经坚持了好几个小时,我无法根据我的资料找出如何解决它在这里或谷歌上找到。
我有一个连接到 GPS 和收音机的 arduino,并试图将 GPS 信号广播到我的收音机。我现在要做的是将 GPS 中的 NMEA 语句放入变量“文本”中,但我对这个错误感到困惑,我认为这是由于数组造成的。
我的错误发生在这一行:
sprintf(text, char(c));
我尝试了一些不同的方法,但这就是我目前遇到的问题。任何帮助将不胜感激。
#define RADIOPIN 13
#include <string.h>
#include <util/crc16.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
#define GPSECHO true
Adafruit_GPS GPS(&mySerial);
char datastring[80];
char text[80];
void setup() {
Serial.begin(115200);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
delay(3000);
pinMode(RADIOPIN,OUTPUT);
}
void loop(){
gpscheck();
}
void gpscheck(){
char c = GPS.read();
if (c) {
// Serial.print(c);
sprintf(text, char*(c));
Serial.print(text);
}
}
【问题讨论】:
-
GPS.read()只会返回一个字符或一个字符串? -
sprintf(text, char*(c));错了!了解它的用法here。
标签: c++ c arduino arduino-ide