Hi, all,
I am a newbie on C++ and arduino, when I try to get the entry of integer from serial monitor, it runs into some problem. Some println are added into the codes to track the how the codes run.
boolean loopflag=false;
String brandName="";
byte Counts=0;
String buttonName="";
byte getNumber()
{
char * value="";
String s="";
s=getChars();
Serial.println("***DEBUG GETNUMBER s-->");
Serial.println(s);
///***************************************
for (int i=0; i< s.length(); i++)
{
value[i]=s[i];
//value[i+1]='\0';
Serial.println("value[i]");
Serial.println(value);
}
////****************************************
Serial.println("***DEBUG GETNUMBER value-->");
Serial.println(value);
Serial.println("***END DEBUG***");
Serial.println("");
return atoi(value);
}
String getChars(void)
{
char rcv=' ';
String str;
while (rcv!='\n')
{
if (rcv!=' ')
str += rcv;
if (Serial.available()>0)
rcv=Serial.read();
else
rcv=' ';
}
return str;
}
void setup()
{
Serial.begin(9600);
Serial.print("Please enter the brand name of your remote:");
brandName=getChars();
Serial.println(brandName);
Serial.println("Please enter how many records ");
Serial.println("would be recorded per button:");
Counts = getNumber();
Serial.println("");
Serial.println("Counts=");
Serial.println(Counts,DEC);
Serial.println(" ***END SETUP*** ");
}
void loop()
{
if (!loopflag)
{
Serial.println("loop procedure");
loopflag=true;
}
}
The serial monitor would display like these:
Please enter the brand name of your remote:SONY
Please enter how many records
would be recorded per button:
*DEBUG GETNUMBER s-->
248
value
2loop procedure
value
24oop procedure
value
248op procedure
***DEBUG GETNUMBER value-->
248op procedure
END DEBUG
248op procedure
248op procedure
Counts=
248
END SETUP
48op procedure
_When I would like to display the value, it seems print out the its value and, strangely, the part of the string in loop() procedure. And the code calls ' Serial.println("");' once in line 32 in setup(), but there are two lines are printed out as '248op procedure'.
Would you please tell me what the errors I have made in the above codes.
BR,
Ardypro_