I have the Mega ASK R3 board with the Ethernet Shield R3.. I have been working on a sketch for simple LED control. All of my testing has been using the lower pins 2 through 8 while testing functionality. Everything seems to be working correctly when using pins 2 through 8. I tried changing the pin assignments to use pins on the digital header, pins 35 through 42.. The 2560 PinMapping chart indicates where those pins are found on the header but some pins show in the wrong spot and others don't show up at all. Out of the 8 pins, I can only find pins 38 and 39. Pin 38 shows up on header pin 47 and Pin 39 shows up on header pin 27.
Am I missing something very basic? I'm pulling my hair out on this one.
My sketch for reference.
#include <Ethernet.h>
#include <SPI.h>
//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
String inString = String(35);
String Led;
int led[] = {00, 35, 36, 37, 38, 39, 40, 41, 42};
//int led[] = {00, 2, 3, 4, 5, 6, 7, 8};
int numofleds = 42; //numofleds
//String value[] = {"on","on","on","on","on","on","on","on","on"}; //startup all led are off
EthernetServer server(80);
String data;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
//set pin mode
for (int j = 35; j < (numofleds + 1); j++){
pinMode(led[j], OUTPUT);
digitalWrite(led[j],LOW);
}
// for (int k = 45; k < (numofinputs + 1); k++){
// pinMode(led[k], INPUT);
Serial.println("Serial READY");
Serial.println("Ethernet READY");
Serial.println("Server READY");
}
void loop()
{
EthernetClient client = server.available();
if(client){
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if(client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (inString.length() < 35) {
inString.concat(c);
}
if (c == '\n' && current_line_is_blank) {
Serial.println(inString);
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// client.println("<html><body><form method=get>");
// client.println("<p>Led controller</p>");
for(int i = 35; i < (numofleds + 1) ;i++){
Led = String("led") + i;
if(inString.indexOf(Led+"=on")>0 || inString.indexOf("all=on")>0){
Serial.println(Led+"on");
digitalWrite(led[i], HIGH);
// value[i] = "off";
}else if(inString.indexOf(Led+"=off")>0 || inString.indexOf("all=off")>0 ){
Serial.println(Led+"off");
digitalWrite(led[i], LOW);
// value[i] = "on";
}
else if(inString.indexOf(Led+"=status")>0 || inString.indexOf("all=status")>0 ){
Serial.println(Led+"status");
if (digitalRead (led[i]) == 0) {
client.println("off");
}
else {
client.println("on");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
inString = "";
client.stop();
}
}
}
}
}
Moderator edit: [code] ... [/code] tags added. (Nick Gammon)