Go Down

Topic: Push Button to turn on LED?? (Read 1 time) previous topic - next topic

walshlg

Please help, I hope this is the right place to post this, I bought the Makershed Project pack for Arduino, Makershield and trying to go through the Getting started with the arduino book.

Having problems with MakerShield I think:
From Book example 2: turning on an LED while the button is pressed
USING A MAKERSHIELD the button (Btn1) push seems to pull the pin low so the logic reverses, thought it was simple but not working.

I have the button input (pin 7) connected to Btn1 pin that is connected to 5v through a 1K resistor so when button not pressed, it floats high (it will light an LED) and when btn is pressed it goes low.

However my LED does nothing (and no error messages) in the following simple sketch:

//Button_01
//example turn on led when button is pressed
//using the makershield

#define LED 13    //led output pin
#define BUTTON 7  //button INput pin

int BUTTONSTATE= 1;  //variable to go low when button is pressed
                     // button press opens sink to ground

void setup () {
  pinMode (LED, OUTPUT);
  pinMode (BUTTON, INPUT);
}
void  loop(){
  BUTTONSTATE == digitalRead(BUTTON);  //check  and store LOW if the button was pressed
  if (BUTTONSTATE == LOW) {
    digitalWrite(LED,HIGH);    //if button pressed turn LED ON
  }
  else {
    digitalWrite(LED, LOW);
  }   
}

groundFungus

You are using two equal signs in an assignment statement.  Assignment:  var = something.  Two equal signs for comparison: if(var==something)

walshlg

Arggh, yes that was it,

thanks for the help

Go Up