how to use getch() ; function in arduino programming as in c ( in conio.h ) is there any header file for getch (); ?
uint8_t getch()
{
while( !Serial.available());
return (uint8_t)Serial.read();
}
?
uint8_t getch()
{
while( !Serial.available());
return (uint8_t)Serial.read();
}
getch() returns an int (16 bit) not a byte/char. But as Serial can't do EOF. Go on then.
Mark
getch() returns an int (16 bit) not a byte/char.
Hence the (completely safe) cast.
But, I just double-checked the prototype for getch, and it returns an "int" anyway.
"getch" is a bit of a mongrel - it can even be a macro.
I don't see any advantage in wrapping Serial.available() and Serial.read() into a getch() function.
There are many situations in which a simple Serial.read() is a poor solution and a more comprehensive system of gathering Serial data is advisable.
Hiding these potential problems in a wrapper that just adds extra code without adding value does not make any sense.
...R