hello to all,
I'm trying to read data from serial
I would like to use these data to make operations with the types INT.
I wrote this sketch:
char t[3];
int a=0;
int b=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{
for (int i=0;i<2;i++){
if (Serial.available()>0){
t[i]=Serial.read();
t[2]=0;
a++;
}
}
if (a>0){
Serial.print(t[0]);
Serial.print(t[1]);
Serial.print(t[2]);
b++;
a=0;
}
delay (2000);
if (b>0){
int c= atoi(t);//convert t[] to int c
c=c+2;
Serial.print(c);
b=0;
}
}
}
but if I write for example 58, the result is:
5 78 10
the addition was
5 +2 = 7
8 +2 = 10
and not 58+2=60
and does not write the first values ??of v [] and after the value of c, it switches between them!
Why????
sorry for my english
ok I'm stupid!!
an error in}
the for loop is closed at the end of loop () and not immediately after reading the characters from the serial
Thanks to all and sorry!