Hardware Reference
In-Depth Information
set up as per Figure 3-1 and plugged in, start the serial monitor in the Arduino IDE and match the baud rate of 9600.
When the button is pressed, it causes an h or an l character to be displayed for a high or low state change. Sending the
Arduino an a or an s will turn on or off the LED.
Figure 3-1. Arduino circuit for Listing 3-1
Arduino Serial Functions
Listed following is a reference of Arduino serial functions and what they are used for. These functions reside in the
predefined Serial object. To call any of the serial functions, use Serial. before the name, like so:
Serial.begin(9600);
void begin(speed) : Opens and sets a serial port at a baud speed equal to an unsigned long.
Returns nothing.
void end() : Closes the serial connection, releasing the TX and RX pins.
int available() : Checks for data in the serial buffer and returns the number of bytes in the buffer.
int read() : Returns the first incoming byte in the serial buffer as an int , and then removes
the byte. Successive reads will move through the buffer, much like dealing a deck of cards.
int peek() : Reads the incoming serial buffer's first byte, returns as an int , and leaves the data
in the buffer. This function is like peeking at the top card of a deck of cards.
void flush() : Clears the serial buffer's data. flush() will clear data after the buffer data is sent out.
size_t print / println (value, format) : Sends a human-readable translation of data.
Digits are sent as ASCII-equivalent strings, and characters are sent as bytes. This function can
have a format of DEC, HEX, BIN, or OCT. format can also be used to define the number of
bytes to send. println is the same as print , except it sends a new line to the end of the value.
Returns the number of bytes sent; reading is not required.
 
Search WWH ::




Custom Search