Bien, el código anterior arroja los valores medidos (distancias) impresos en el "monitor serial" que posee el ide de arduino.
Bueno como mi intención es mostrar estos valores por la web, he utilizado y modificado el programa del servidor web que viene como ejemplo en el cual muestra en la web los valores que lee de los 6 pines analógicos que tiene la tarjeta arduino.
Bueno agregandole el programa anterior de tal manera que también muestre los valores del ultrasónico por la web, tengo este código de programa:
//Mostrar valores del ultrasónico en servidor arduino
#include <SPI.h>
#include <Ethernet.h>
#include <Ultrasonic.h>
Ultrasonic ultrasonic(9,8,17400); // (Trig PIN,Echo PIN)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,4);
EthernetServer server(80);
void setup()
{
// start the Ethernet connection and the server:
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended, so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//Mostrar valores del ultrasónico
client.print("valores del sensor ultrasonico ");
client.print(ultrasonic.Ranging(CM));
client.println("<br />");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("<br />");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
.
Bueno el detalle es que al armarlo, no funciona; es decir que los valores del sensor ultrasónico no se muestran en el servidor web...
Talvés tenga que agregar algunas funciones de código más, no sé. Espero puedan orientarme al respecto...
Desde ya muchas gracias a todos los que deseen orientarme