Go Down

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


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 :smiley-eek:. Code Below.
Also, I would love advice  :smiley-red: 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;
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


if (buttonState = HIGH)

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


Thanks WizenedEE. I totally was blind to that. It's like having one of
of those sentences.
(see what I did there?)

Go Up