Hello,
I am using an arduino uno with an ethernet module. I have wired the ethernet module correctly to the arduino, so that the webpage correctly shows in the browser with the ip address. But when I click on the button to turn the led on, the led does not turn on, even though I have made an if statement with the return result of that button. I have also attatched the led to digital pin 8, and checked that it works
The code is below
I have also attached a screenshot of the html webpage....
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xEF, 0xED
};
EthernetServer server (80);
String readString;
int led = 8;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (led, OUTPUT);
Ethernet.begin(mac);
server.begin();
Serial.print("Server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
if (readString.length() < 100) {
readString += c;
}
if (c = '\n') {
Serial.print(readString);
client.println("< HTTP / 1.1 200 OK >");
client.print("<Connection-Type: text/html>");
client.println("<Connection: close>");
client.println("");
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head>");
client.println("<title>Control the LCD connected to the Arduino</title>");
client.println("<h1 style=text-align:center>Control the LCD connected to the Arduino</h1>");
client.println("<head>");
client.println("<body>");
client.println("<p></p>");
client.println("<p>This is a test paragraph</p>");
client.println("<a href=\"/?button1on\"\"><button> Turn led on </button></a>");
client.println("<a href=\"/?button2off\"\"><button> Turn led off </button></a>");
client.println("<body style=background-colour:powderblue>");
delay(1);
client.stop();
if (readString.indexOf ("?button1on") > 0) {
digitalWrite(led, HIGH);
}
if (readString.indexOf ("?button2off") > 0) {
digitalWrite(led, LOW);
}
readString = "";
}
}
}
}
}
Any help would be really helpful... Thanks.
