My aim is reading some string from serial for example 234124!3455addg#5867 if the program sees ! it should start to add it to a char array and if it sees # it should return the first 4 elements of that char array for my example the return should be 3455. How can I solve it? I made this using String class but I need to implement it to char array. I am quite new on arduino so please be clear thank you. Here is my code:
char Tmp[200];
bool b=0;
int counter;
void setup() {
Serial.begin(9600);
Serial.println("Enter a Message");
}
void loop() {
while (Serial.available() > 0)
{
char recieved = Serial.read();
if (recieved=='!' || b==1){
if(b!=1){
b=1;
counter=0;
}
b=1;
counter++;
Tmp[counter]=Serial.read();
delay(10);
}
else if (recieved=='#'){
counter++;
Tmp[counter]='\0';
newPack(Tmp);
return;
}
}}