#include <LiquidCrystal.h>// initialize the library with the numbers of the interface pinsLiquidCrystal lcd(12, 11, 5, 4, 3, 2);char txt;int val;void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello ASIMO"); Serial.begin(9600);}void loop() { lcd.setCursor(16,0); while(Serial.available()>0) { txt=Serial.read(); val=txt; if (val==126) { break; } lcd.autoscroll(); lcd.print(txt); delay(2000); } lcd.noAutoscroll(); delay(5000); lcd.clear(); lcd.setCursor(16,0);}
Hindi sa serial.avalable() yung kailangan i-clear, serial.avalable() simply checks if there is new data in the serial buffer. To clear the serial buffer, simply execute a serial.flush().
kung tama understanding ko before ang purpose ng flush is to clear the read buffer, ngayon eh magiintay sya ma maclear(maintransmit lahat) ang write buffer....http://arduino.cc/en/Serial/FlushWaits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)
usefull sana yun kung binavalidate yung mga byte, kapag nakadetect ng isang byte na mali, no need na basahin na lahat ng transmitted data, therefore pwede natin iflush to clear the buffers....