multipal char to int   HELP! plzzzzz

hi everyone im having a hack at a dedicated servo arduino mainly for learning.

ok so it reads from serial something like

$SERVO,123,30,100,180,55*

checks it mainly starts with $SERVO
then finds the , and the final *

my problem is that i need to convert the “123” into a int but seen as its split up into
linea[8]=49 <char
linea[9]=50 <char
linea[10]=51 <char
i know i can just subtract 48 to get the int i want but i need to cram the remaning “1"2"3” into
servo[1] = 123 <int

if someone unserstands me please help!
heres my code:

#include <string.h>
#include <ctype.h>

int servo[5] = {'1', '2', '3', '4', '5'};   //'1-5' = output pins
int rotation[5] = {90, 90, 90, 90, 90};
int pw = 0;


int inputbyte =-1;
char linea[300] = "";
char servopin[7] = "$SERVO";
int conta = 0;
int cont = 0;
int indices[5];
int match=0;

void setup(){  
  Serial.begin(9600);
  
  for(int f=0; f<5; f++){
    pinMode(servo[f], OUTPUT);
  }
  for (int i=0;i<300;i++){       // Initialize a buffer for received data
  linea[i]=' ';
  }
}


void loop(){
  
  
  //put bytes from serial into linea
  conta=0;
  match=0;
  inputbyte=Serial.read();
  if(inputbyte == -1){
    //servos();
  } else {
    for(int h=0; h<=60; h++){
     linea[h]=inputbyte;        // If there is serial port data, it is put in the buffer
     inputbyte=Serial.read();
     delay(2);
    }
    //serial Checker  (prints linea)
    
    Serial.println("linea =");
    for(int y=0; y<60; y++){
      Serial.print(linea[y]);
    }
    
    Serial.println("");
    Serial.println("");
    
    
    //prints the servopin 2 serial 2 check it
    Serial.println("servopin = ");
    for (int i=0;i<7;i++){
    Serial.print(servopin[i]);
    }
    
    Serial.println("");
    Serial.println("");


    //Checks the start = servopin
    for (int i=0;i<7;i++){
      if (linea[i+1]==servopin[i]){
      match++;
      Serial.println("positave");
      } else {
       Serial.println("negitave"); 
      }
    }
    Serial.println("");
    Serial.println("");
    //if 5 or more characters match
    if(match==5){
      Serial.println("got to here!");
      Serial.println("");
      Serial.println("");
      //find the , seperators and the * end
      for (int i=0;i<300;i++){
        if (linea[i]==','){   // check for the position of the  "," separator
          indices[cont]=i;
          cont++;
        }
        if (linea[i]=='*'){    // ... and the "*"
          indices[5]=i;
          cont++;
        }
      }
      
      for(int j=0; j<5; j++){
        Serial.print("indices "); 
        Serial.print(j);
        Serial.print(" = ");
        Serial.println(indices[j]);
      }
      
      
      //THIS BIT HERE!!!!!
    for(int c=0; c<5; c++){
      for(int i=0; i<5; i++){
    
      Serial.println(linea[i]);
      Serial.println(servo[i]);
    }
    }
    }
  }
}

yes i know theres a lot of junk in there its just because im debugging it

thanks so mych in advance

You can do something like:

linea[8]=49 <char ‘1’
linea[9]=50 <char ‘2’
linea[10]=51 <char ‘3’

servo[1] = (linea[8] - ‘0’) * 100 + (linea[9] - ‘0’) * 10 + (linea[10] - ‘0’);

  • Ben

You can do something like:

linea[8]=49 <char ‘1’
linea[9]=50 <char ‘2’
linea[10]=51 <char ‘3’

servo[1] = (linea[8] - ‘0’) * 100 + (linea[9] - ‘0’) * 10 + (linea[10] - ‘0’);

  • Ben

OOH!!
ben thankyou so much for you quick reply and solving answer i appreciate it so much.

ps there needs to be a rep thing on here to aplaud helpful and contributing members

No problem, good luck with your project!

  • Ben