I am new to Arduino and I have the following:
int delaynum;
char cval[12];
void setup()
{
Serial.begin(9600);
Serial.print("Enter Number");
Serial.flush();
int i=0;
while(i<12)
{
if(Serial.available()>0)
{
char ch=Serial.read();
if(ch>='0'&&ch<='9')
{
cval[i]=ch;
i++;
}
else
{
cval[i]=0;
delaynum=atoi(cval);
break;
}
}
}
}
void loop()
{
Serial.println(delaynum);
exit(0);
}
The code output in virtual bread board:(i Entered 100)
But when i remove Serial.flush()
The output like (i Entered 100)
I am Expecting the output:
Enter Number (I want to enter number 100 after the output)
100
Why the code not working ?
I am using Arduino IDE with virtual bread board(ATMega328p)