Programming Support needed

I am new in arduino programming and trying to make a simple program that allows changing the led brightness every time a push button which is assigned to input PIN# 2 is pressed. The output is PIN# 9 (PWM).
Unfortunately the LED is not even getting ON. Can someone assist in checking the below program please.
Thank you.

int led = 9;
int button = 2;
int Bcount = -1;
byte ledflicker={0,25,50,75,100,125,150,175,200,225,255};

void setup() {

pinMode(button,INPUT);
pinMode(led,OUTPUT);
}

void loop() {

if (button == HIGH)
{
Bcount = Bcount + 1;
analogWrite(led,ledflicker[Bcount]);
delay(200);
}
if (Bcount==10)
{
Bcount=-1;
}
}

How is your button wired?

  if (button == HIGH)

button is declared with a value of 2 and is never changed in the program so will always be HIGH

Did you mean

  if (digitalRead(button) == HIGH)

Also, how is the button input wired ?

Maybe also take a look at the state change example in the IDE.
loop() loops at a ferocious rate.

It's awkward the way you pre-increment the index, this forces you to use a signed variable and initialize it to a value outside the array, -1. You should increment after use, instead like:

  analogWrite(led,ledflicker[Bcount]);
  Bcount = Bcount + 1;

A bounds test should never just check for equality, it is safer to use with an inequality, like

if (Bcount >= 10)

Also you should auto format your code using ctrl-T to enforce readable indentation.

Hi frednas,

You should post code by using code-tags
There is an automatic function for doing this inthe Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy to forum"
  3. paste clipboard into write-window of a posting

best regards Stefan