Proofread Code Please?

Hello,

I am working on the second version of my robot arm, and for this one i’m writting a program in Max to control it, and most of the information will be transferred serially. If anyone can help me with the Arduino side, it would be greatly appreciated. I can go more into detail if needed.

#include <Servo.h>

Servo Servo1;
Servo Servo2;
Servo Servo3; 
Servo Servo4;
Servo Servo5;

void setup()
{
  Servo1.attach(4);
    Servo2.attach(5);
      Servo3.attach(6);
        Servo4.attach(7);
          Servo5.attach(8);

            Serial.begin(9600);
            }

            void loop()
            {
              if(Serial.available())
              {
                byte bytereceipt = Serial.read();

                if(bytereceipt == 201);
                {
                  delay(5);
                  bytereceipt = Serial.read();
                  Servo1.write(bytereceipt);
                  Serial.write(bytereceipt);
                  }
                 else if(bytereceipt == 202)
                  {
                  delay(5);
                  bytereceipt = Serial.read();
                  Servo2.write(bytereceipt);
                  Serial.write(bytereceipt);
                }
                else if (bytereceipt == 202)
                {
                  delay(5);
                  bytereciept = Serial.read();
                  Servo3.write(bytereceipt);
                  Serial.write(bytereceipt);
                }
                else if (bytereceipt == 203)
                {
                  delay(5);
                  bytereciept = Serial.read();
                  Servo4.write(bytereceipt);
                  Serial.write(bytereceipt);
                }
                else if (bytereceipt == 204)
                {
                  delay(5);
                  bytereciept = Serial.read();
                  Servo5.write(bytereceipt);
                  Serial.write(bytereceipt);
                }
              }
            }

JBatista:
I can go more into detail if needed.

It's generally a good idea to post what issue you're having. Specifically, contrasting what the code is supposed to be doing to what it is actually doing.

You make two checks for ‘else if (bytereceipt == 202)’
so your checks only go from 201 to 204, you want it to go to 205?

Here is a version of your code using arrays:

#include <Servo.h>

Servo Servos[ 5 ];

void setup()
{
  for( char i = 0 ; i < 5 ; ++i )
    Servos[ i ].attach( i + 4 );
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available())
  {
    byte bytereceipt = Serial.read();
    
    if( bytereceipt >= 201 && bytereceipt <= 205 ){
      delay(5);
      Servos[ bytereceipt - 201 ].write(bytereceipt);
      Serial.write(bytereceipt);
    }
  }
}

Code edited to remove second read from serial.

It gives me this…

This code is controlling multiple inputs. Yours just looks like one.

Check the spelling, the names don't match.

JBatista:
This code is controlling multiple inputs. Yours just looks like one.

It uses arrays to control all 5 servos: Arrays - C++ Tutorials

                if(bytereceipt == 201);

Generally speaking, if statements shouldn't end with semicolons.

If it helps, this is what I plan to do… (without the 6th servo input)