hey there noob here,
I am trying to combine two different sketch in one sketch for obtaining respective output.
Follwing are the code and there output
////***HMR code****////
char message[] = "$PTNTHPR,74.5,N,-2.9,N,3.3,N,*24"; // an example string
char* next; //pointer to substring (token)
float value;
float ans;
float divde;
void setup() {
Serial.begin(9600);
}
void loop() {
// char message[] = "$PTNTHPR,74.5,N,-2.9,N,3.3,N,*24"; // an example string
// char* next; //pointer to substring (token)
// float value;
next = strtok(message, ","); //get first substring (token)
Serial.println(next); // and print "$PTNTHPR"
Serial.print("magnitude : ");
(next = strtok(NULL, ",")); //get and print the string "75.4"
value = atof(next); //convert string to float
Serial.println(value, 4); // and print
Serial.println(ans);
(next = strtok(NULL, ","));
Serial.print("magnitude Status : ");
Serial.println(next);
(next = strtok(NULL, ",")); //get and print the string "-2.9 "
value = atof(next); //convert string to float
Serial.print("pitch: ");
Serial.println(value, 4);
(next = strtok(NULL, ","));
Serial.print("pitch Status : ");
Serial.println(next);
(next = strtok(NULL, ",")); //get and print the string " 3.3 "
value = atof(next); //convert string to float
Serial.print("roll : ");
Serial.println(value, 4);
(next = strtok(NULL, ","));
Serial.print("roll Status : ");
Serial.println(next);
delay(9000);
}
void degree(){
float divide=180/PI;
ans = value*divde;
}
////HMR output////
$PTNTHPR
magnitude : 74.5000
0.00
magnitude Status : N
pitch: -2.9000
pitch Status : N
roll : 3.3000
roll Status : N
$PTNTHPR
////**GPGGA string**//
#include<math.h>
float value;
int D;//integerpart degree
int M;//decimalpart; minutes
int S;// second
void setup(){
Serial.begin(9600);
char message[]=" $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47";
//Serial.println(message);
char*next;// pointer to substring(token)
//float value;// we declared above it for all
next=strtok(message,","); // get first substring token
Serial.println(next); //print GPGGA
Serial.print("UTC: "); //print universal time UTC
(next=strtok(NULL,","));//print next string 123519
value=atof(next); // convert string to float
Serial.println(value,0);
Serial.print("latitude: ");//print latitude
(next=strtok(NULL,","));//print next string
value=atof(next);
//Serial.println(value,4);
DMS(float(value));
Serial.print("Direction: ");// print direction
(next=strtok(NULL,","));
Serial.println(next);
Serial.print("longitude: ");//print longitude
(next=strtok(NULL,","));
value=atof(next);
//Serial.println(value,3);
DMS(float(value));
Serial.print("Direction: ");// print direction
(next=strtok(NULL,","));
Serial.println(next);
Serial.print("fix quality: ");
(next=strtok(NULL,","));
value=atof(next);
Serial.println(value,0);
Serial.print("NO. of Satellites teacked: ");
(next=strtok(NULL,","));
value=atof(next);
Serial.println(value,0);
Serial.print("Horizontal dilution position: ");//print longitude
(next=strtok(NULL,","));
value=atof(next);
Serial.println(value,2);
Serial.print("Altitude,meters: ");
(next=strtok(NULL,","));
value=atof(next);
Serial.print(value ,2);
(next=strtok(NULL,","));
Serial.print(",");
Serial.println(next);
Serial.print("Height,meters: ");//
(next=strtok(NULL,","));
value=atof(next);
Serial.print(value ,2);
(next=strtok(NULL,","));
Serial.print(",");
Serial.println(next);
Serial.print("check sum : ");//print check sum data
(next=strtok(NULL,","));
Serial.println(next);
}
//convert to degree minute second ...........
void DMS(float(value)) {
// put your main code here, to run repeatedly:
//value = Serial.parseFloat();//returns the first valid floating point number from the Serial buffer.
//Serial.print(" DATA: ");
//Serial.println(value,4);
D =(int)value; // gets the first part as going from (casting) // cast is used
//float to int drops the bit after the decimal point
//Serial.print("Degree: ");
Serial.print(D);// print degree
Serial.print("°");// ASCII VALUE FOR °= (ALT +428)
// Serial.println(" ");
// get the second part minutes
M= 10000*(value-D);
//Serial.print("Minutes: ");
Serial.print(M);// print minutes
Serial.print("'");// add minutes (') symbols
//Serial.println("");
// Second part
S=60*(M);
// Serial.print("Second: ");
Serial.print(S);//print second
Serial.print("''");// add second (") symbols
Serial.println("");
}
void loop(){
}
/// GPGGA OUTPUT//
$GPGGA
UTC: 123519
latitude: 4807°380'22800''
Direction: N
longitude: 1131°0'0''
Direction: E
fix quality: 1
NO. of Satellites teacked: 8
Horizontal dilution position: 0.90
Altitude,meters: 545.40,M
Height,meters: 46.90,M
check sum : *47
///