Pages: [1]   Go Down
Author Topic: All pins unused pins HIGH?  (Read 374 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-grin Any ideas?

(code tags added by Moderator)
Code:
/*********************** 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;
}
« Last Edit: November 14, 2012, 09:25:49 am by CrossRoads » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48569
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IF you post your code this ways no one is going to read it boy. smiley-wink
Logged

From Idea To Invention

Valencia, Spain
Online Online
Faraday Member
**
Karma: 144
Posts: 5368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IF you post your code this ways no one is going to read it boy. smiley-wink

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.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Indiana, US
Offline Offline
Full Member
***
Karma: 12
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: November 14, 2012, 08:36:53 am by patduino » Logged

There are 10 types of people in the world, those that understand binary, and those that don't.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26554
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: