Go Down

Topic: "LOW" doesnt actually keep the pin off (Read 832 times) previous topic - next topic

David2204

I just recieved my Arduino board so I'm still trying simple stuff, so don't laugh :-/

I was trying to make a led light light up, whenever you press any of the 4 buttons, but when the program starts first there is a weak light, and when I press a button it lights up a little bit brighter. I just dont get it... I tell the board to keep the pin low when there are no buttons pressed. What is the problem?

Here is the code (the buttons are attached to pins 9-12 and the led is on 13):

int ledPin = 13;
int firstPin = 9;
int secondPin = 10;
int thirdPin = 11;
int fourthPin = 12;
int one = 0;
int two = 0;
int three = 0;
int four = 0;

void setup()
{  
 pinMode(ledPin, OUTPUT);
 pinMode(firstPin, INPUT);
 pinMode(secondPin, INPUT);
 pinMode(thirdPin, INPUT);
 pinMode(fourthPin, INPUT);  
}
 
void loop()
{
 one = digitalRead(whtPin);
 two = digitalRead(bluPin);
 three = digitalRead(redPin);
 four = digitalRead(yelPin);
 if(one == HIGH || two == HIGH || three = HIGH || four = HIGH)
 {
   digitalWrite(ledPin, HIGH);
 }
     
 else { digitalWrite(ledPin, LOW);}
}

Daniel

#1
Jun 29, 2007, 11:14 pm Last Edit: Jun 29, 2007, 11:18 pm by Daniel Reason: 1
hi

does this actually compile?

Code: [Select]
one = digitalRead(whtPin);
 two = digitalRead(bluPin);
 three = digitalRead(redPin);
 four = digitalRead(yelPin);

 
The whtPin, redPin etc variables are not declared anywhere.
Also, do you have pull-up or pull-down resistors on the switches? Without them the input pin values float, and in  turn this  makes the "if loop" go back and forth, giving you a dim light.

D

mellis

Also you need two equals signs == not one = for a comparison, the three = HIGH should be three == HIGH, etc.


David2204

eh... i just changed the variable names so its more understandable here, but it seems that i forgot a few ;)
and yyes, i does compile... its prolly like Daniel said about the resistors.

Thank you ;)

Go Up