Button code not working

So, my goal is to do that, if the button is pressed, an LED will light at an intensity controlled by a potentiometer. However, it doesn't work (the button part, I think). Here's my code :

int buttonPin = 7;
int ledPin = 9;
int potPin = A0;

void setup() {

Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
pinMode(7, INPUT);}

void loop() {

int buttonState;
int val;

val = analogRead(A0);
buttonState == digitalRead(7);
if (buttonState == HIGH){
val = map(val, 0, 1023, 0, 255);
analogWrite(9, val);
}
Serial.println(val);

delay(15);
}

No
buttonState == digitalRead(7);

Yes
buttonState = digitalRead(7);

== Comparison
= Assignment

Thanks so much ! It works just fine now :slight_smile:

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How do you have your button wired?
Between input 7 and 5V?
If so do you have a 10K resistor between input 7 and gnd?

Tom.. :slight_smile:

Just a side note...

Why declare "int potPin = A0;", if you're not going to use it? (pinMode(A0, INPUT); along with other declarations)