tmd3:
OK, I think that you're saying that you're connecting a wire to pin 31, and leaving the other end of the wire not connected to anything. You're asking why you might read a HIGH on pin 31.
If I have your question right, I would guess that pin 31, configured as an input, is floating, and has no particular logical state. It will read HIGH or LOW depending on the characteristics of the electric field that the pin, and the wire that's connected to it, are immersed in. See a discussion here, under the heading, "Feeding."
Does that mean that you're sourcing 10 milliamps into the pin? That would mean that you're applying a positive voltage to a relatively high impedance. My guess is that almost the entire 10 milliamps flows from the pin through its protection diode into VCC. To push 10 milliamps into an input pin, the voltage has to be higher than VCC - certainly high enough to be read as a HIGH. Your code is looking for a LOW to turn on the lights. You're applying a signal that doesn't pass the test, so the sketch doesn't execute the statements in the block.
Maybe a schematic, and a complete, minimal sketch that illustrates the problem, would help.
Thank you for the reply tm3. I'm working off a project booklet actually, and this particular project simulates two traffic lights. Here is the illustration they give:
http://s14.postimg.org/7v3zwrfq9/schematic.png
Here is the code they provide (I've changed the pin numbers for my own appropriation)
#define westButton 31
#define eastButton 33
#define westRed 50
#define westYellow 48
#define westGreen 46
#define eastRed 40
#define eastYellow 38
#define eastGreen 36
#define yellowBlinkTime 500 // 0.5 seconds for yellow light blink
boolean trafficWest = true; // west = true, east = false
int flowTime = 1000; // amount of time to let traffic flow
int changeDelay = 2000; // amount of time between color changes
void setup()
{
// setup digital I/O pins
pinMode(westButton, INPUT);
pinMode(eastButton, INPUT);
pinMode(westRed, OUTPUT);
pinMode(westYellow, OUTPUT);
pinMode(westGreen, OUTPUT);
pinMode(eastRed, OUTPUT);
pinMode(eastYellow, OUTPUT);
pinMode(eastGreen, OUTPUT);
// set initial state for lights - west side is green first
digitalWrite(westRed, LOW);
digitalWrite(westYellow, LOW);
digitalWrite(westGreen, HIGH);
digitalWrite(eastRed, HIGH);
digitalWrite(eastYellow, LOW);
digitalWrite(eastGreen, LOW);
}
void loop()
{
if ( digitalRead(westButton) == HIGH ) // request west>east traffic flow
{
if ( trafficWest != true )
// only continue if traffic flowing in the opposite (east) direction
{
trafficWest = true; // change traffic flow flag to west>east
delay(flowTime); // give time for traffic to flow
digitalWrite(eastGreen, LOW); // change east-facing lights from green
// to yellow to red
digitalWrite(eastYellow, HIGH);
delay(changeDelay);
digitalWrite(eastYellow, LOW);
digitalWrite(eastRed, HIGH);
delay(changeDelay);
for ( int a = 0; a < 5; a++ ) // blink yellow light
{
digitalWrite(westYellow, LOW);
delay(yellowBlinkTime);
digitalWrite(westYellow, HIGH);
delay(yellowBlinkTime);
}
digitalWrite(westYellow, LOW);
digitalWrite(westRed, LOW); // change west-facing lights from red to green
digitalWrite(westGreen, HIGH);
}
}
if ( digitalRead(eastButton) == HIGH ) // request east>west traffic flow
{
if ( trafficWest == true )
// only continue if traffic flow is in the opposite (west) direction
{
trafficWest = false; // change traffic flow flag to east>west
delay(flowTime); // give time for traffic to flow
digitalWrite(westGreen, LOW);
// change west lights from green to yellow to red
digitalWrite(westYellow, HIGH);
delay(changeDelay);
digitalWrite(westYellow, LOW);
digitalWrite(westRed, HIGH);
delay(changeDelay);
for ( int a = 0 ; a < 5 ; a++ ) // blink yellow light
{
digitalWrite(eastYellow, LOW);
delay(yellowBlinkTime);
digitalWrite(eastYellow, HIGH);
delay(yellowBlinkTime);
}
digitalWrite(eastYellow, LOW);
digitalWrite(eastRed, LOW); // change east-facing lights from red to green
digitalWrite(eastGreen, HIGH);
}
}
}
I've connected my components as the schematic outlines. However, the "traffic lights" go through their cycle without me pressing either switch.
According to the link you have provided, I think I just need to connect the 10k resistors to a ground.
With regards to using INPUT_PULLUP, yes, I've just realised my error. I quickly passed my eyes over the official description, seeing the words "inverts the behaviour", but did not see that I require a ground for the signalling.