iwant aid for buttontoggle

Hello all, i am trying to modify this code to open and close a led with only 1 button with no results
for pin 4

#include <EtherCard.h> 

#define DEFAULT_ENC28J60_CONTROL_CS 53
#define SPI_SS 53
#define SPI_MOSI 51
#define SPI_MISO 50
#define SPI_SCK 52

static byte mymac[] = { 
  0x5A,0x5A,0x5A,0x5A,0x5A,0x5A };

static byte myip[] = { 
  192,168,1,222 };

byte Ethernet::buffer[900];
BufferFiller bfill;

int LedPins[] = {
  2,3,4,5,6,7};

boolean PinStatus[] = {
  1,2,3,4,5,6};
  





const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";

//------------

void homePage()
{
  bfill.emit_p(PSTR("$F"
    "<title>ArduinoPIN Webserver</title>" 
    "Relay 1: <a href=\"?ArduinoPIN1=$F\">$F</a>
"
    "Relay 2: <a href=\"?ArduinoPIN2=$F\">$F</a>
"  
    "Relay 3: <a href=\"?ArduinoPIN3=$F\">$F</a>
"
    "Relay 5: <a href=\"?ArduinoPIN5=$F\">$F</a>
"
        "Relay 6: <a href=\"?ArduinoPIN6=$F\">$F</a>
"

    "Relay 4: <a href=\"?ArduinoPIN4=$F\">$F</a>"   
),

  http_OK,
  PinStatus[1]?PSTR("off"):PSTR("on"),
  PinStatus[1]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
  PinStatus[2]?PSTR("off"):PSTR("on"),
  PinStatus[2]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
  PinStatus[3]?PSTR("off"):PSTR("on"),
  PinStatus[3]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
    PinStatus[5]?PSTR("off"):PSTR("on"),
  PinStatus[5]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
      PinStatus[6]?PSTR("off"):PSTR("on"),
  PinStatus[6]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
  PinStatus[4]?PSTR("off"):PSTR("on"),
  PinStatus[4]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"));
}

//------------------------



void setup()
{
  Serial.begin(9600);
pinMode(53,OUTPUT);
  if (ether.begin(sizeof Ethernet::buffer, mymac,53) == 0);

  if (!ether.dhcpSetup()); 

 
  ether.printIp("My Router IP: ", ether.myip); 
  
  


  ether.printIp("My SET IP: ", ether.myip); 

 
  
  for(int i = 0; i <= 6; i++)
  {
    pinMode(LedPins[i],OUTPUT); 
    digitalWrite (LedPins[i],HIGH);
    PinStatus[i]=false;
  }  
}

// --------------------------------------

void loop()
{

  delay(1); 

  word len = ether.packetReceive();   
  word pos = ether.packetLoop(len);   

  if (pos) {
    bfill = ether.tcpOffset();
    char *data = (char *) Ethernet::buffer + pos;
    if (strncmp("GET /", data, 5) != 0) {
      bfill.emit_p(http_Unauthorized);
    }
   
   
    else {

      data += 5;
      if (data[0] == ' ') {       
        homePage(); // Return home page ßêùî âèÿâëåíî çì³íè íà ñòîð³íö³, çàïóñêàºìî ôóíêö³þ.
        for (int i = 0; i <= 6; i++)digitalWrite(LedPins[i],!PinStatus[i+1]);
      }

      // "16" = ê³ëüê³ñòü ñèìâîë³â "?ArduinoPIN1=on ".
      else if (strncmp("?ArduinoPIN1=on ", data, 16) == 0) {
        PinStatus[1] = true;        
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?ArduinoPIN2=on ", data, 16) == 0) {
        PinStatus[2] = true;        
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?ArduinoPIN3=on ", data, 16) == 0) {
        PinStatus[3] = true;        
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?ArduinoPIN4=on ", data, 16) == 0) {
        PinStatus[4] = true;        
        bfill.emit_p(http_Found);
      
      }
      
       else if (strncmp("?ArduinoPIN5=on ", data, 16) == 0) {
        PinStatus[5] = true;        
        bfill.emit_p(http_Found);
      
      }
       else if (strncmp("?ArduinoPIN6=on ", data, 16) == 0) {
        PinStatus[6] = true;        
        bfill.emit_p(http_Found);
      
      }


      //------------------------------------------------------  


      else if (strncmp("?ArduinoPIN1=off ", data, 17) == 0) {
        PinStatus[1] = false;        
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?ArduinoPIN2=off ", data, 17) == 0) {
        PinStatus[2] = false;        
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?ArduinoPIN3=off ", data, 17) == 0) {
        PinStatus[3] = false;        
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?ArduinoPIN4=off ", data, 17) == 0) {
        PinStatus[4] = false;        
        bfill.emit_p(http_Found);
      }
       else if (strncmp("?ArduinoPIN5=off ", data, 17) == 0) {
        PinStatus[5] = false;        
        bfill.emit_p(http_Found);
      }

      else if (strncmp("?ArduinoPIN6=off ", data, 17) == 0) {
        PinStatus[6] = false;        
        bfill.emit_p(http_Found);
      }
      




      else {
        // Page not found
        bfill.emit_p(http_Unauthorized);
      }
    }
    ether.httpServerReply(bfill.position());    // send http response
  }
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.... :slight_smile:

 int LedPins[] = {2,3,4,5,6,7};


for(int i = 0; i <= 6; i++)
  {
    pinMode(LedPins,OUTPUT);
    digitalWrite (LedPins,HIGH);

This doesn't look right to me. Isn't LedPins missing an index? There are other places in the code where LedPins is in a for loop without the index.

Please use CODE tags when posting code. Does your code really need all of that white space?

this code is work on arduino mega verrry well but i am trying to modify this code to open and close a led with only 1 button web page please help me

int LedPins[] = {2,3,4,5,6,7};


for(int i = 0; i <= 6; i++)

A six element array has no element six.

AWOL:

int LedPins[] = {2,3,4,5,6,7};

for(int i = 0; i <= 6; i++)



A six element array has no element six.

idont understand
ihave six element and work good but the button toggle failed to add in sketch

The valid indices for a six element array are 0, 1, 2, 3, 4 and 5.
6 does not appear in that list, and you shouldn't use it to access you array "LedPins".

ahma2001:
i dont understand
i have six element and work good but the button toggle failed to add in sketch

All good then. Go for it... it seems like you have solved the question by yourself.