Another "lvalue required as left operand of assignment" question.

First off, I’m very new to Arduino and programming. I’m familiar with analog circuitry, but new to programming. I also want to preface this with yes, I did do research but a lot of the threads I came across are above my head in programming language and how people explained this error. So what I tried to do was take the “State Change Detection” template from Arduino’s site and edit it to detect when I push a button, and then turn on an LED for one second when it recognizes the button being pushed. I’m sure there is probably a way simpler way to do this than using a lot of the programming lines used in the template, but again, I’m new. So with this code:

const int buttonPin = A0;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(8, OUTPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
digitalWrite(8 = HIGH);
delay (1000);
digitalWrite(8 = LOW);
}
}
}

I’m getting the “lvalue required as left operand of assignment” error on the “digitalWrite(8 = LOW)” line. Can someone please explain in simple terms what is meant by this error and how to correct it? Thanks in advance.

digitalWrite(8 = HIGH);

The digitalWrite() function takes two arguments - a pin number and a state.

I have no idea what you are trying to do here, but you can not assign a value to 8. 8 is a constant.

digitalWrite(8, HIGH);

I explained in my original post what I was trying to do (turn an LED on for one second when a button is pushed).

I do see what I was doing wrong now in regards to using "8= LOW" instead of"8, LOW". Thanks for pointing that out.

However, it still isn't working. The software doesn't report any errors, but the circuit isn't working like it's supposed to. It seems Pin 8 is outputting a constant 5v rather than only outputting 5v when the button is pressed. I'll have to troubleshoot that.

EDIT:
So I just realized that when I press the on-board button/switch, it makes the LED turn off for one second. Which is the opposite of what I'm trying to do. Additionally, I'm trying to use an external button hooked up to analog input A0. Can you not use analog inputs as a sensing input pin?

You can use analog pins for digital I/O.

Perhaps you need to initialize that pin with pinMode(A0, INPUT_PULLUP); to activate the internal pullup resistor - assuming you are not using an external resistor. Without a resistor the pin "floats" and may give random values.

If you use INPUT_PULLUP (which is recommended) and wire your switch to connect the pin to GND when pressed it will read LOW when pressed and HIGH when not pressed.

...R

I am using an external resistor. I've basically got a breadboard with a simple circuit set up with an LED, resistor (to ground), and a switch. My "sample" or "sensing" wire is taken off of the cathode to A0. The power supply to the bread board is wired to be from Pin 8. I did change the code to read "pinMode(A0, INPUT)" as opposed to "pinMode(buttonPin)" and still the same thing.

MERRITTJW1:
and still the same thing.

Please remind us what the problem is. I am rather confused.

...R

Pin 8 still has a constant output voltage as opposed to only having a voltage output when the button/switch is pressed. I'm trying to make output pin 8 only put out power when the button is pressed.

Please post the updated code in a new message, using code tags.

I finally figured it out after messing around with it for a while. I even figured out how to monitor three separate inputs and output on three separate outputs respectively. Thanks for the help!

You need to tell the sketch to remember the last button state

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      digitalWrite(8, HIGH);
      delay (1000);
      digitalWrite(8, LOW);
   }
  }

  // v v v add this here v v v 
  lastButtonState = buttonState;
  // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  

}