Hello! I am having a little trouble with my code.
// We’ll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
// XBee’s DOUT (TX) is connected to pin 2 (Arduino’s Software RX)
// XBee’s DIN (RX) is connected to pin 3 (Arduino’s Software TX)
SoftwareSerial XBee(5, 4); // RX, TXString motorfunc;
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
}void loop()
{
//if (Serial.available())
{ //If data comes in from serial monitor, send it out to XBee
// XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
motorfunc = Serial.read();if (motorfunc==“Distance: 9mm”); {
Serial.println(“stop”);
}
I want to read the data coming out of my Serial monitor and use it into another if loop. For example: I am reading ‘Distance: 9mm’ from my Serial Monitor, I want to use it to do another if loop like if ‘Distance: 9mm, a “stop” will print in the Serial Monitor.’ I cant get it to work. I tried it and the word ‘stop’ only prints but the Distance: 9mm prints in a different way
Dstop
istop
sstop
tstop
astop
nstop
cstop
estop
:stop
stop
9stop
mstop
mstop
this is what appears in the Serial Monitor. Any help is appreciated! Thanks!