Hi,
I would like to show the status of my reed-contacts (PIN 5 and PIN 6) on a website. But unfortunatly if i plug the reed-contact i get the button (that should be green,yellow or red) 100 times instead of only 1 time. I cant find a command to show the status only once. How can i repair my skript that it only show the information once.
I know that the while command is the reason but i dont know what to use else...
I am new to Arduino programming and i would be glad if you could help me.
This is my main problem:
{
while (digitalRead(Window_Bot_Pin))
{
digitalWrite(Window_Led_Pin1, HIGH);
client.println("<svg xmlns=http://www.w3.org/2000/svg version=1.1>");
client.println("<circle cx=100 cy=50 r=30 stroke=black strok-width=2 fill=yellow />");
client.println("</svg>");
}
if(!digitalRead(Window_Top_Pin))
{
digitalWrite(Window_Led_Pin1, LOW);
}
while (digitalRead(Window_Top_Pin))
{
digitalWrite(Window_Led_Pin2, HIGH);
client.println("<svg xmlns=http://www.w3.org/2000/svg version=1.1>");
client.println("<circle cx=100 cy=50 r=30 stroke=black strok-width=2 fill=green />");
client.println("</svg>");
}
if(!digitalRead(Window_Bot_Pin))
{
digitalWrite(Window_Led_Pin2, LOW);
client.println("<svg xmlns=http://www.w3.org/2000/svg version=1.1>");
client.println("<circle cx=100 cy=50 r=30 stroke=black strok-width=2 fill=red />");
client.println("</svg>");
}
}
Here the whole code:
/*
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10, 14, 5, 234);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
int Window_Led_Pin1 = 13;
int Window_Led_Pin2 = 12;
int Window_Top_Pin = 6;
int Window_Bot_Pin = 5;
int Status = 0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(Window_Led_Pin1, OUTPUT);
pinMode(Window_Led_Pin2, OUTPUT);
pinMode(Window_Top_Pin, INPUT);
pinMode(Window_Bot_Pin, INPUT);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// 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("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<head>");
client.println("<title>");
client.print("Fenstersensor");
client.println("</title>");
client.println("</head>");
client.println("<h1>");
client.println("Fenstersensor");
client.println("</h1>");
client.println("Window");
// output the value of each analog input pin
{
while (digitalRead(Window_Bot_Pin))
{
digitalWrite(Window_Led_Pin1, HIGH);
client.println("<svg xmlns=http://www.w3.org/2000/svg version=1.1>");
client.println("<circle cx=100 cy=50 r=30 stroke=black strok-width=2 fill=yellow />");
client.println("</svg>");
}
if(!digitalRead(Window_Top_Pin))
{
digitalWrite(Window_Led_Pin1, LOW);
}
while (digitalRead(Window_Top_Pin))
{
digitalWrite(Window_Led_Pin2, HIGH);
client.println("<svg xmlns=http://www.w3.org/2000/svg version=1.1>");
client.println("<circle cx=100 cy=50 r=30 stroke=black strok-width=2 fill=green />");
client.println("</svg>");
}
if(!digitalRead(Window_Bot_Pin))
{
digitalWrite(Window_Led_Pin2, LOW);
client.println("<svg xmlns=http://www.w3.org/2000/svg version=1.1>");
client.println("<circle cx=100 cy=50 r=30 stroke=black strok-width=2 fill=red />");
client.println("</svg>");
}
}
client.println("</html>");
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();
Serial.println("client disonnected");
}
}