I am currently working on control two linear actuators using two joysticks wireless thru xbee. I m trying to split the analogRead (incoming data).
This is my transmitter code:
const int joyStickPin = A0;
const int joyStickPin2 = A4;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(“J”);
Serial.println(analogRead(joyStickPin));
Serial.print(“K”);
Serial.println(analogRead(joyStickPin2));
delay(1000);
}
Receiver code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available() > 0) {
int x = Serial.read();
if (Serial.read() == ‘J’){
Serial.print(x);
}
if (Serial.read() == ‘K’){
Serial.print(x);
}
}
}
**I duno if my code is correct or not.
What i want to do is i test with the serial monitor. I want to receive the data separately for ‘J’ and ‘K’.
but after i try many times, the result i get from serial monitor always show:
J509
K522
I want to separate the data J and K. Is it possible to do that?anyone can help?