Go Down

### Topic: NOOB of NOOBS can't figure out what's wrong? (Read 758 times)previous topic - next topic

#### kerbaltron

##### Feb 12, 2012, 05:41 am
I just built Make: Getting Started with Arduino Example 03C and the LED stays on
even after I push the button. The circuit I built looks right, but I am wondering if
I'm missing something in my code. Please help . Code Below.
Also, I would love advice  on whether there is a good place for Noobs to go to get help
with their code or tutoring. I live in San Francisco, just in case you think the
best thing is to go to classes to learn.

/*This is a sketch that turns on an LED when a button
is pushed and keeps it on after it is released
including simple de-bouncing using a delay*/

#define LED 11 // the pin for the LED
#define BUTTON 7 //the input pin where the pushbutton is connected
int BUTTONState = 0;//this will measure whether there is current flowing
//through the BUTTON
int old_BUTTONState = 0;//this will check if there was current flowing
//before by Delay milliseconds away
int LEDState = 0; //This will be used to turn the LED on and off
int Delay = 10;

void setup()
{
pinMode(LED, OUTPUT);//tell Arduino LED is an output
pinMode(BUTTON, INPUT);//tell Arduino BUTTON is an input
}

void loop()
{
BUTTONState = digitalRead(BUTTON);//read BUTTON's state and store it

//check if there was a transition
if ((BUTTONState = HIGH) && (old_BUTTONState = HIGH))
{
LEDState = 1 - LEDState;
delay(Delay);
}

old_BUTTONState = BUTTONState; //store the current BUTTON State as
//the old State after <Delay/100> seconds
if (BUTTONState == HIGH)
{
digitalWrite(LED, HIGH);//turn on LED
} else {
digitalWrite(LED, LOW);//turn off LED
}
}

#### WizenedEE

#1
##### Feb 12, 2012, 05:50 am
if (buttonState = HIGH)

= sets a variable to a value
== checks to see if the variable is equal to a value.

#### kerbaltron

#2
##### Feb 14, 2012, 01:38 am
Thanks WizenedEE. I totally was blind to that. It's like having one of
of those sentences.
(see what I did there?)

Go Up

Please enter a valid email to subscribe