Skip to content
Snippets Groups Projects
Commit 92f3c4ed authored by Zhaoliang Zheng's avatar Zhaoliang Zheng
Browse files

upgrade the distance and send it all together

parent 4df58dbc
Branches
No related merge requests found
......@@ -3,7 +3,8 @@
#include <Wire.h>
// REPLACE WITH THE MAC Address of your receiver (SLAVE)
uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C};
// uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C}; // #4
uint8_t broadcastAddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0x91, 0x74}; // #1
String success;
// Define variables to store BME280 readings to be sent
......@@ -11,6 +12,7 @@ String strdata = "";
String valdata = "";
String quedata = "";
int count = 0;
int count_digit = 0;
// Define variables to store incoming readings
String incomingStr = "";
......@@ -100,9 +102,11 @@ void loop()
sentData.StrD = strdata;
Serial.println(sentData.StrD);
}
if (isDigit(inChar) || inChar == '.' || inChar == '-'){
if ((isDigit(inChar) || inChar == '.' || inChar == '-') && (count_digit <= 9)){
valdata += char(inChar);
count_digit += 1;
}
if (inChar == '?'){
quedata += char(inChar);
sentData.QueM = quedata;
......@@ -119,8 +123,8 @@ void loop()
sentData.QueM = "";
}else{
// sentData.ValD = 0;
Serial.print("ValD");
Serial.println(sentData.ValD);
Serial.print("ValD");
Serial.println(sentData.ValD);
Serial.print("QueM:");
Serial.println(sentData.QueM);
}
......@@ -135,6 +139,7 @@ void loop()
strdata = "";
quedata = "";
count = 0;
count_digit = 0;
}
}
......
......@@ -4,7 +4,8 @@
// REPLACE WITH THE MAC Address of your receiver (MASTER)
// Slave: 40:F5:20:44:B6:4C
uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x4A, 0xCF, 0x00};
// uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x4A, 0xCF, 0x00};
uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C}; // #4
String success;
// Define variables to store BME280 readings to be sent
......@@ -27,9 +28,8 @@ int8_t threshold[6] = {Lmin, Lmax, Amin, Amax, Bmin, Bmax};
int base_speed = 70;
int seeking_speed = 70;
int lidar_thres = 300; // mm
int gbx = 0, gby = 0;
int gbx = 0, gby = 0,gbd = 0;
double gbc = 0;
// =====================================================================================
//Structure the sending data
......@@ -262,8 +262,13 @@ void ChangeVariables(){
lidar_thres = getDoubleVal(strData,"lth",valData,lidar_thres);
//------ green ball x, y----
gbx = getDoubleVal(strData,"gbx",valData,gbx);
gby = getDoubleVal(strData,"gby",valData,gby);
gbc = getDoubleVal(strData,"gbc",valData,gbc);
gbx = gbc /1000000;
gby = fmod(gbc,1000000)/1000;//(gbc.toInt() % 1000000)/1000;
gbd = fmod(gbc,1000); // gbc.toInt() % 1000;
// gbx = getDoubleVal(strData,"gbx",valData,gbx);
// gby = getDoubleVal(strData,"gby",valData,gby);
}
......@@ -338,12 +343,17 @@ void print_allvariables(){
Serial.print("Kpy:");
Serial.println(Kpy);
Serial.print("|");
Serial.print("gbc:");
Serial.print(gbc);
Serial.print("|");
Serial.print("gbx:");
Serial.print(gbx);
Serial.print("|");
Serial.print("gby:");
Serial.println(gby);
Serial.print(gby);
Serial.print("gbd:");
Serial.println(gbd);
Serial.println("---------------------------\n");
print_count +=1 ;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment