void loop()
{
if(Serial.available()){
while(Serial.available())
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ junk = Serial.read() ; } // clear the serial buffer
Dear all I found above program from the Internet and it has three Serial.available() functions
1
if(Serial.available()){
2
while(Serial.available())
3
while (Serial.available() > 0)
I thinks we can manage single Serial.available() Function
Please advice the reason to use three Serial.available() functions
PA3040:
Please advice the reason to use three Serial.available() functions
The author of the code wasn't very smart?
The first if is completely not needed. The two while loops are doing different things entirely. But anytime you see the words "clear the Serial buffer" in some code your first thought should be that the person who wrote it was an idiot and didn't know much about writing code.
Those two while expressions are functionally equivalent. Like I said, whomever wrote this wasn't much of a coder. It would probably be best to forget you ever saw that code.
Delta_G:
Those two while expressions are functionally equivalent. Like I said, whomever wrote this wasn't much of a coder. It would probably be best to forget you ever saw that code.
Does this function (Serial.available() > 0) read the UDRn Register of MEGA 328
PA3040:
Can we able to see the ARDUINO library file that what happen in side the Serial.available() Function
Please advice
Thanks in advance
Yes, look in the folder where you installed the Arduino IDE. All of the source code is there. You're looking for HardwareSerial.h and HardwareSerial.cpp