Serial communication-2 analog inputs to 2 PWM outputs

Hello,
I am trying to write two separate codes for a project that takes 2 potentiometers as inputs, goes into an arduino, and is wirelessly transmitted via Xbee to another xbee/arduino, where it will output two PWM signals (one based off of each potentiometer).

I can get it to work well using one potentiometer and LED, but when I try to add the second pair, I get stuck with the coding.
Here is the code I have for the transmitter side:

//Constants:
const int potPin1 = A0; //Pot input at Arduino A0 pin
const int potPin2 = A5; //Pot input at Arduino A5 pin
//Variables:
int value1 ; //Value from pot1
int value2;//Value from pot2

void setup() {

  //Start the serial communication
  Serial.begin(19200); //Starts serial communication @ 19200bps (Same as Xbee)

}

void loop() {
   
    //Read the analog value from pot and store it to "value" variable
    value1 = analogRead(A0);//Sets value1 as analog input from port A0
  //  value2 = analogRead(A5);//Sets value2 as analog input from port A5
   
    //Map the analog value to pwm value
    value1 = map (value1, 0, 1023, 0, 255);// maps original values of 0-1023 to 0-255
    // value2 = map (value2, 0, 1023, 0, 255);// maps original values of 0-1023 to 0-255
     
  //Send the message:
  Serial.print('<');  //Starting symbol pot1
  Serial.print(value1);//Sends value1 from 0 to 255
  Serial.println('>');//Ending symbol pot1

  Serial.print('{');//Starting symbol pot2
  Serial.print('value2');//Sends value2 from 0 to 255
  Serial.print('}');//ending symbol pot2


}

I am not sure if I should get rid of the ending symbol on value1 and the starting symbol of value2, or keep it the way it is. This code outputs as <255>{255}<255>{255}… and so on(example).

The main confusion I have is the receiver side of the code, here is my attempt so far:

  //Constants
const int ledPin = 3; //Led to Arduino pin 3 (PWM)
const int ledPin2 = 5; //Led to Arduino pin 5 (PWM)

//Variables
bool started= false;//True: Message is strated
bool ended   = false;//True: Message is finished
char incomingByte ; //Variable to store the incoming byte
char msg[3]; //Message1 - array1 from 0 to 2 for PWM 0-255 values
char msg2[3];//Message2 - array2 from 0 to 2 for PWM 0-255 values
byte index;  //Index of array 1
byte index2;//Index of array2

void setup() {

  //Start the serial communication
  Serial.begin(19200); //Starts serial communication @ 19200bps (Same as Xbee)
  pinMode(ledPin, OUTPUT);//Sets pin 3 as a PWM output
  pinMode(ledPin2, OUTPUT);//Sets pin 5 as a PWM output
}

void loop() {
 
  while (Serial.available()>0){
    //Read the incoming byte
    incomingByte = Serial.read();
   
    if(incomingByte == '<' || '{')  //NOT SURE IF THIS WILL WORK
    {
     started = true;
     index = 0;
     msg[index] = '\0'; // Throw away any incomplete packet
   }
   else if(incomingByte == '>' || '}')
   {
     ended = true;
     break; // Done reading - exit from while loop!
   }
   //Read the message!
   else
   {
     if(index < 4) // Make sure there is room
     {
       msg[index] = incomingByte; // Add char to array
       index++;
       msg[index] = '\0'; // Add NULL to end
     }
   }
 }
 
 if(started && ended)
 {
   int value = atoi(msg);
   analogWrite(ledPin, value);
   analogWrite(ledPin2,value);
   //Serial.println(value); //Only for debugging
   index = 0;
   msg[index] = '\0';
   started = false;
   ended = false;
 }
}

I do not know if I should make multiple arrays, or keep it all as one and somehow extract them out separately. I am really stuck here and would appreciate any help.
Thank you very much!

Cross posting is very much frowned upon in this forum. Worse than not using code tags. I have reported this post to the forum moderators.

Thanks for reporting this PaulRB!

I've deleted your other cross post @westonhayle.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I tried to delete the last one but didnt know how... really guys cmon im new here

westonhayle:
I tried to delete the last one but didnt know how… really guys cmon im new here

Really westonhayle cmon that’s the same excuse given by every new forum member who thinks they don’t need to read the forum guide before posting.

You can’t delete the first post in a topic. But you can click “report to moderator” and ask them to delete it. Or you can modify it and fix it (More->Modify).

   if(incomingByte == '<' || '{')  //NOT SURE IF THIS WILL WORK

No, you must write

   if(incomingByte == '<' || incomingByte == '{')
 if(started && ended)
 {
   int value = atoi(msg);

The problem at this point is that the code has “forgotten” whether it read “<” or “{”, so it does not know which pin to update. You could save that character and use it later.

started = true;
startingByte = incomingByte;

then you can write

if (startingByte == '<')
  analogWrite(ledPin, value);
else
  analogWrite(ledPin2,value);

To make your code much simpler, you could use Serial.parseInt(). Then you would not need arrays, array indexes or atoi(). Like this (untested):

//Constants
const int ledPin = 3; //Led to Arduino pin 3 (PWM)
const int ledPin2 = 5; //Led to Arduino pin 5 (PWM)

void setup() {

  //Start the serial communication
  Serial.begin(19200); //Starts serial communication @ 19200bps (Same as Xbee)
  pinMode(ledPin, OUTPUT);//Sets pin 3 as a PWM output
  pinMode(ledPin2, OUTPUT);//Sets pin 5 as a PWM output
}

void loop() {

  if (Serial.available() > 0) {
    //Read the incoming byte
    char incomingByte = Serial.read();

    if (incomingByte == '<') {
      int value = Serial.parseInt();
      analogWrite(ledPin, value);
      Serial.read(); //Read and discard the '>' symbol
    }
    else if (incomingByte == '{') {
      int value = Serial.parseInt();
      analogWrite(ledPin2, value);
      Serial.read(); //Read and discard the '}' symbol
    }
  }
}

Thank you very much for all of your help! I will continue to keep learning the rules of the forum and I apologize for that as it is very confusing at first. I was able to finish my code with your help and have it functional now! Thanks!!