Hardware Reference
In-Depth Information
Continued from previous page.
void setup()
{
// get the list of serial ports:
println(Serial.list());
// open the serial port appropriate to your computer:
myPort = new Serial(this, Serial.list()[0], 9600);
// configure the serial object to buffer text until it receives a
// linefeed character:
myPort.bufferUntil(linefeed);
}
void draw()
{
//no action in the draw loop
}
void serialEvent(Serial myPort) {
// print any string that comes in serially to the monitor pane
print(myPort.readString());
}
void keyReleased() {
// if any key is pressed, take the next step:
switch (step) {
case 0:
// open a connection to the server in question:
myPort.write("C");
// add one to step so that the next keystroke causes the next step:
step++;
break;
case 1:
// send an HTTP GET request
myPort.write("GET /~myaccount/index.html HTTP/1.1\n");
myPort.write("HOST: myserver.com \n\n");
step++;
break;
}
}
8 Change these to
match your own server.
Starting with this sketch as a base, you could
work out the whole logic of the HTTP exchange
in Processing, then convert your sketch into an
Arduino sketch.
Don't get too caught up in the technical details of your
program when working this way. You're still going to have to
deal with the details of the microcontroller program even-
tually. However, it often helps to see the similarities and
differences between two languages when you're working
on a problem. It helps you concentrate on the logic that
underlies them.
X
This approach allows you to work out the logical flow of
an application in an environment with which you might be
more familiar. It removes the complications of the micro-
controller environment, allowing you to concentrate on the
sequence of messages and the actions that trigger them.
 
Search WWH ::




Custom Search