Pages: [1]   Go Down
Author Topic: "LOW" doesnt actually keep the pin off  (Read 712 times)
0 Members and 1 Guest are viewing this topic.
Slovenia
Offline Offline
Newbie
*
Karma: 0
Posts: 4
ArduinoBT owner
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);}
}
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

hi

does this actually compile?

Code:
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
« Last Edit: June 29, 2007, 04:18:11 pm by Daniel » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Slovenia
Offline Offline
Newbie
*
Karma: 0
Posts: 4
ArduinoBT owner
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thank you smiley-wink
Logged

Pages: [1]   Go Up
Jump to: