Go Down

Topic: All pins unused pins HIGH? (Read 457 times) previous topic - next topic

Nov 14, 2012, 10:27 am Last Edit: Nov 14, 2012, 03:25 pm by CrossRoads Reason: 1
Hi guys,

I am using a bit of modified code, but for the life of me I cannot work out why all my pins are set to high, pins 2,3,4 start off as usual, but I can poke a LED into any other and its on :D Any ideas?

(code tags added by Moderator)
Code: [Select]

/*********************** Marque's Arduino Controller Example ***********************/
/***********************  for questions: marque.l@gmail.com  ***********************/
/*
In the android app settingsscreen you can set up you IP and port.
For this example you need to call prefix 1 "B" and prefix 2 "C".
*/
#include <Ethernet.h>
#include <HTTPClient.h>
#include <SPI.h>

int RecievedString;
int valueB;
int valueC;
String readString = String(20);

int rm2light1 = 4;
int fishlight = 2;
int fishpump = 3;


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(80);   // port to listen on
EthernetClient client;

char content_main_top[] = "<body bgcolor=black><font color=white><center>";
char S1[] = "Room 2, Light 1 is on " ;
char S2[] = "Room 2, Light 1 is off" ;
char S3[] = "Fish Light is on";
char S4[] = "Fish Light is off";
char S5[] = "Fish Pump is on";
char S6[] = "Fish Pump is off";
char S404[] = "Not Found";

/************************** Setup **********************/
void setup()
{
 Serial.begin(9600);
 Serial.println("Getting IP......");
 Ethernet.begin(mac);
 Serial.print("My IP address: ");
 Ethernet.localIP().printTo(Serial);
 Serial.println();
 Serial.print("Gateway IP address is ");
 Ethernet.gatewayIP().printTo(Serial);
 Serial.println();
 Serial.print("DNS IP address is ");
 Ethernet.dnsServerIP().printTo(Serial);
 Serial.println();
 pinMode(rm2light1, OUTPUT);
 pinMode(fishlight, OUTPUT);
 pinMode(fishpump, OUTPUT);
 Serial.print("Initialising rm2light1 ");
 Serial.print("Initialising fishlight ");
 Serial.print("Initialising fishpump ");
 Serial.println();
 digitalWrite(rm2light1, LOW);
 digitalWrite(fishlight, LOW);
 digitalWrite(fishpump, LOW);
}
void loop()
{

checkclient();
}

void checkclient()
{
 EthernetClient client = server.available();
 if (client)  
 {
   boolean sentHeader = false;
   while (client.connected())
   {
     if (client.available())
     {
       if(!sentHeader){
       client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println();
         sentHeader = true;
       }
        char c = client.read();
        if (readString.length() < 20)
        Serial.print(c);
        {readString.concat(c);}
        if (c == 'H')
        {
          Serial.println();
          int Is = readString.indexOf("/");
          int Iq = readString.indexOf("?");
          int Ib = readString.indexOf("b");
          int Ic = readString.indexOf("c");
          if(readString.indexOf("?") > 1)
          {
            if (Ib == (Iq+1))
            {
              char carray[5];
              readString.toCharArray( carray,5,(Ib+1));
              Serial.println(carray);
               valueB = atof(carray);
              Serial.print("B is now: ");
              Serial.println(valueB);
              client.print (content_main_top);
              client.print("B is now: ");
              client.print(valueB);
            }
           else if (Ic == (Iq+1))
            {
              char carray[5];
              readString.toCharArray( carray,5,(Ic+1));
              Serial.println(carray);
               valueC = atof(carray);
              Serial.print("C is now: ");
              Serial.println(valueC);
              client.print (content_main_top);
              client.print("C is now: ");
              client.print(valueC);
            }
            else
            {
              char carray[2];
              readString.toCharArray( carray,2,(Iq+1));
              RecievedString = atoi(carray);
              switch (RecievedString) {
              case 1: action(1, client);digitalWrite(rm2light1, HIGH);break;
              case 2: action(2, client);digitalWrite(rm2light1, LOW);break;
              case 3: action(3, client);digitalWrite(fishlight, HIGH);break;
              case 4: action(4, client);digitalWrite(fishlight, LOW);break;
              case 5: action(5, client);digitalWrite(fishpump, HIGH);break;
              case 6: action(6, client);digitalWrite(fishpump, LOW);break;
              default: action(404, client);
              }
            }
         delay(1);
            client.stop();
            readString="";
            client.read(); client.read();
          }
        if (Iq < 0)
        {
        action(404, client);
        delay(1);
        client.stop();
        readString="";
        client.read(); client.read();
        }
         delay(1);
        client.stop();
        readString="";
        client.read(); client.read();
      }
    }
  }
}
}

void action(int x, EthernetClient client)
{  
 if (x == 1)
 {client.print (content_main_top);
  client.println(S1);
  Serial.println(S1);
 }
if (x == 2)
 {client.print (content_main_top);
  client.println(S2);
  Serial.println(S2);
 }
if (x == 3)
 {client.print (content_main_top);
  client.println(S3);
  Serial.println(S3);
 }
if (x == 4)
 {client.print (content_main_top);
  client.println(S4);
  Serial.println(S4);
 }
if (x == 5)
 {client.print (content_main_top);
  client.println(S5);
  Serial.println(S5);
 }
if (x == 6)
 {client.print (content_main_top);
  client.println(S6);
  Serial.println(S6);
 }
if (x == 404)
 {client.print (content_main_top);
  client.println(S404);
  Serial.println(S404);
 }
x=0;
}

PaulS

Quote
All pins unused pins HIGH?

No. Unless declared as OUTPUT, pins are INPUT. Input pins with nothing connected to them have undefined state.

Psst. That's NOT how to post code. Use the # icon to generate tags, and post your code between them (where the cursor is).

Cybernetician

IF you post your code this ways no one is going to read it boy. ;)
From Idea To Invention

fungus


IF you post your code this ways no one is going to read it boy. ;)


I thought posts at the top of the forums called "Read this before posting a question..." were only for stupid people. Certainly not for people like SamuelFreeman.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

patduino

#4
Nov 14, 2012, 02:30 pm Last Edit: Nov 14, 2012, 02:36 pm by patduino Reason: 1
Quick side note... I'm fairly new to these forums too, and have been looking for guidance and instructions on how to post correctly. The site is large, and I haven't found anything yet -- am I looking in the wrong spots? Can you direct me to the right spot?  Thanks!

Also, I thought unused pins are set to input and were pulled high by default.

Edit: interesting... Just after posting this, I saw the 'read this first...' link you mentioned (I did look before posting this, by the way).  It wasn't there when I looked earlier ?! Maybe I inadvertently set a filter. Hmmm
There are 10 types of people in the world, those that understand binary, and those that don't.

CrossRoads

"Also, I thought unused pins are set to input and were pulled high by default."

Input pins are not pulled high by default.  I think there is even something in the release notes stating that.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up