hello, i am trying to use enc28j60 with arduino so i came across this code which is most suitable for my project
// A simple web server to turn 2 LED on or off
#include "etherShield.h"
#include "ETHER_28J60.h"
int outputPin = 6; // LED1 to pin 6
int anotherOutputPin = 7; // LED2 to pin 7
static uint8_t mac[6] = {
0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {
192, 168, 1, 15}; // IP address for the webserver
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
void setup()
{
e.setup(mac, ip, port);
pinMode(outputPin, OUTPUT);
pinMode(anotherOutputPin, OUTPUT);
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print("<h1><a href='/?led1=off&led2=off'>Arduino Web Remote</a></h1>");
if (strcmp(params, "?led1=on&led2=off") == 0)
{
digitalWrite(outputPin, HIGH);
digitalWrite(anotherOutputPin, LOW);
e.print("<a href='?led1=off&led2=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED1 IS ON</button></a><a href='?led1=on&led2=on'>
<button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED2 IS OFF</button></a>");
}
else if (strcmp(params, "?led1=off&led2=on") == 0)
{
digitalWrite(outputPin, LOW);
digitalWrite(anotherOutputPin, HIGH);
e.print("<a href='?led1=on&led2=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED1 IS OFF</button></a><a href='?led1=off&led2=off'>
<button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED2 IS ON</button></a>");
}
else if (strcmp(params, "?led1=off&led2=off") == 0)
{
digitalWrite(outputPin, LOW);
digitalWrite(anotherOutputPin, LOW);
e.print("<a href='?led1=on&led2=off'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED1 IS OFF</button></a><a href='?led1=off&led2=on'>
<button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED2 IS OFF</button></a>");
}
else if (strcmp(params, "?led1=on&led2=on") == 0)
{
digitalWrite(outputPin, HIGH);
digitalWrite(anotherOutputPin, HIGH);
e.print("<a href='?led1=off&led2=on'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED1 IS ON</button></a><a href='?led1=on&led2=off'>
<button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED2 IS ON</button></a>");
}
e.respond();
}
}
for two leds it has 2x2=4 combinations.
i want to control 5 leds so using else ifs i can actually extend the code but for 5 leds using the else if's it would take 5x5= 25 loops and the program size would be very big..
so i am trying to make it as a function so i can pass 5 parameters, the state of all the 5 leds ie on or off
the problem is it has bit of html and i am not sure how to proceed so if any one is kind enough please guide me to build a 5 led webserver using the code