Hello guys.
I was needed to insert delay time for my other program I mean to pause it.
So I come up with this code... But I really don't like it.
So is there any other elegant way to write it. Thanks.
int emount = 0;
int delay1 = 0;
String Str;
if(Serial.available()>0)
{
Str = Serial.readString();
emount = Str.length();
if(emount == 1)
{
delay1 = Str[0] -48;
}
if(emount == 2)
{
delay1 = (Str[0]-48) * 10 + Str[1]-48;
}
if(emount == 3)
{
delay1 = (Str[0] -48) * 100 + (Str[1] -48) *10 + (Str[2]-48);
}
if(emount == 4)
{
delay1 = (Str[0] -48) * 1000 + (Str[1] -48) *100 + (Str[2]-48)*10 +Str[3] -48 ;
}
if(emount == 5)
{
delay1 = (Str[0] -48) * 10000 + (Str[1] -48) *1000 + (Str[2]-48)*100 + (Str[3]-48)*10 + Str[4] -48 ;
}
Serial.println(delay1);