As with the LCD library discussed in
Chapter 9
, a standard Arduino library takes care
of interfacing with the Ethernet shield.
The
setup
function initializes the Ethernet library using the
mac
and IP addresses that
you set earlier.
The
loop
function is responsible for servicing any requests that come to the web server
from a browser. If a request
is waiting for a response,
then calling
server.available
will
return a client.
A client is an object; you will learn a bit more
about what this means in
Chapter 11
. But for now, all that you need to know is that whether a client exists (tested by
the first
if
statement); then you can then determine whether
it is connected to the web
server by calling
client.connected
.
The next three lines of code print out a return header. This just tells the browser what
type of content to display. In this case, the browser is to display HTML content.
Once the header has been written, all that remains is to write the remaining HTML back
to the browser. This must include the usual
and
tags, and also includes a
header tag and two
tags that will display the value on the analog input A0 and
the
value returned by the
millis
function; that value is the
number of milliseconds since
the Arduino was last reset.
Finally,
client.stop
tells the browser that the message is complete.
The browser then
displays the page.
Dostları ilə paylaş: