30-04-2012, 16:01
|
|
|
חבר מתאריך: 02.06.03
הודעות: 1,224
|
|
עזרה בכתיבת תוכנית המשלב ++C ו-HTML
אז ככה
יש לי מיקרובקר שמחובר לחיישן
ברגע שהחיישן מופעל נדלקת לי נורה אדומה למשך 5 שניות . ואז חוזרת נורה ירוקה (עד שהחיישן יופעל שוב....)
עשיתי תנאי שאם החיישן עובד ירשום הודעה "warning - sensor on"
וכל עוד הכל בסדר "all good".
הבעיה היא שמשום מה הוא לא מראה לי את ההודעה השניה , של הפעלת החיישן
#include <SPI.h>
#include <Ethernet.h>
IPAddress ip(10,0,0,155); // ip in lan
EthernetServer server(80); //server is using port 80
int sensor=4;
int GreenLED=9;
int RedLED=7;
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
pinMode(GreenLED,OUTPUT);
pinMode(RedLED,OUTPUT);
pinMode(sensor,INPUT);
}
void loop()
{
if (digitalRead(sensor) ==HIGH) // Green LED
{
digitalWrite(RedLED, LOW);
digitalWrite(GreenLED,HIGH);
msg();
}
else
{
digitalWrite(GreenLED,LOW); // Red LED
digitalWrite(RedLED,HIGH);
msg();
delay(5000);
}
}
void msg()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// see if HTTP request has ended with blank line
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();
//meta-refresh page every 1 seconds
client.println("<HTML>");
client.print("<HEAD>");
client.print("<meta http-equiv=\"refresh\" content=\"1\">");
client.print("<TITLE /> sensor-Test</title>");
client.print("</head>");
client.println("<BODY>");
client.print(" autorefresh test ");
client.println("<br />");
// printing the message
client.print("sensor is ");
if (digitalRead(sensorl) ==HIGH)
{
client.print("All Good");
client.print("<br />");
}
else
{
client.print("Warning ");
client.print("<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();
}
}
_____________________________________
It is nice to be importent but it's more importent to be nice
|