برای این که مستر ( master) اطلاعات gps را به برد اسلیو ( slave ) ارسال کند در کد زیر چه تغییری باید انجام داد ؟
کد:
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
const int sentenceSize = 80;
char sentence[sentenceSize];
#include <Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
gpsSerial.begin(9600);
}
byte x = 0;
void loop()
{
static int i = 0;
if (gpsSerial.available())
{
char ch = gpsSerial.read();
if (ch != '\n' && i < sentenceSize)
{
sentence[i] = ch;
i++;
}
else
{
sentence[i] = '\0';
i = 0;
displayGPS();
}
}
}
void displayGPS()
{
char field[20];
getField(field, 0);
if (strcmp(field, "$GPRMC") == 0)
{
Serial.print("Lat: ");
getField(field, 3); // number
Serial.print(field);
getField(field, 4); // N/S
Serial.print(field);
Serial.print(" Long: ");
getField(field, 5); // number
Serial.print(field);
getField(field, 6); // E/W
Serial.println(field);
}
}
void getField(char* buffer, int index)
{
int sentencePos = 0;
int fieldPos = 0;
int commaCount = 0;
while (sentencePos < sentenceSize)
{
if (sentence[sentencePos] == ',')
{
commaCount ++;
sentencePos ++;
}
if (commaCount == index)
{
buffer[fieldPos] = sentence[sentencePos];
fieldPos ++;
}
sentencePos ++;
}
buffer[fieldPos] = '\0';
Wire.beginTransmission(4); // transmit to device #4
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(500);
}
لطفا کمک کنید .
ممنون می شم .