[Resolved] Dimming doesn't (Re-submitting after edits)

Guys
First, I am fairly new to this game, so please forgive my ignorance and appartent stupidity at times.
I am putting together a sketch to enable me to control multiple O/Ps using one of those little chinese keypads.
I have, with help from a couple of you guys, managed to get the array indexing to work (first bash at arrays).
I have hit another snag with pin 3 and one of my functions. All the function is doing, at the moment, is fading a LED, and the Serial.print is just so that I can see what is happening within the code. Once all the separate button functions work, then I can move on to writing the real functions. One step at a time.
The problem:

#include <IRremote.h>
#include <boarddefs.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

const int RECV_PIN = 11;
unsigned long Code[] = {0xFF6897, 0xFF30CF, 0xFF18E7, 0xFF7A85, 0xFF10EF, 0xFF38C7, 0xFF22DD, 0xFF02FD};


//==============================================================

const byte Button_0_Pin = 2;
const byte Button_1_Pin = 3;                      // PWN pin
const byte Button_2_Pin = 4;
const byte Button_3_Pin = 5;                      // PWM pin
const byte Button_4_Pin = 6;                      // PWM pin
const byte Button_5_Pin = 7;

byte Button_0_Flag = 0;
byte Button_0_Pressed_Flag = 0;
byte Button_1_Flag = 0;
byte Button_1_Pressed_Flag = 0;
byte Button_2_Flag = 0;
byte Button_3_Flag = 0;
byte Button_4_Flag = 0;
byte Button_4_Pressed_Flag = 0;
byte Button_5_Flag = 0;
byte Button_5_Pressed_Flag = 0;
byte Button_Down_Flag = 0;
byte Button_Down_Pressed_Flag = 0;
byte Down_Running_Flag = 0;
byte Button_Up_Flag = 0;
byte Button_Up_Pressed_Flag = 0;
byte Up_Running_Flag = 0;

byte Pin_1_val = 0;
byte Light_Setting = 128;

unsigned long currentMillis = 0;
unsigned long Button_0_Millis = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);

  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  /*          pinMode(4,OUTPUT);
            digitalWrite(4,LOW);*/
  pinMode(5, OUTPUT);
  digitalWrite(5, LOW);
  pinMode(6, OUTPUT);
  digitalWrite(6, LOW);
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);

  irrecv.enableIRIn();                                   // Start the receiver
}
void loop()
{
  currentMillis = millis();

  if (irrecv.decode(&results))
  {
    delay(250);
    for (byte i = 0; i <= 7; i++)
    {
      if (Code[i] == results.value)
      {
        if (i == 0)
        {
          if (Button_0_Pressed_Flag == 0)
          {
            Button_0_Pressed_Flag = 1;
            digitalWrite(2, HIGH);
            Button_0_Millis = millis();
          }
          else
          {
            Button_0_Pressed_Flag = 0;
            digitalWrite(2, LOW);
            break;
          }
        }
        if (i == 1)
        {
          if (Button_1_Pressed_Flag == 0)
          {
            Button_1_Pressed_Flag = 1;
          }
          else
          {
            Button_1_Pressed_Flag = 0;
            digitalWrite(3, LOW);
            break;
          }
        }
/*      if(i == 2)
        {
                    // To define
        }
        if(i == 3)
        {
                    // To define
        }         */
        if (i == 4)
        {
          if (Button_4_Pressed_Flag == 0)
          {
            Button_4_Pressed_Flag = 1;
            analogWrite(6, Light_Setting);
          }
          else
          {
            Button_4_Pressed_Flag = 0;
            digitalWrite(6, LOW);
            break;

          }
        }
        if (i == 5)
        {
          if (Button_5_Pressed_Flag == 0)
          {
            digitalWrite(7, HIGH);
            Button_5_Pressed_Flag = 1;
          }
          else
          {
            digitalWrite(7, LOW);
            Button_5_Pressed_Flag = 0;
          }
        }
        if (i == 6)
        {
          if (Button_Down_Flag == 0)
          {
            Button_Down_Flag = 1;
            Button_Down();
          }
          else
          {
            Button_Down_Flag = 0;
          }

        }
        if (i == 7)
        {
          if (Button_Up_Flag == 0)
          {
            Button_Up_Flag = 1;
            Button_Up();
          }
          else
          {
            Button_Up_Flag = 0;
          }
        }
      }
    }

    irrecv.resume();                             // Receive the next value
  }

  Button_0();
  Button_1();
  Button_Down();
  Button_Up();

}
//============================================================
//                  FUNCTIONS
//============================================================

void Button_0()
{
  if ((Button_0_Pressed_Flag == 1) && (Button_0_Flag == 0))
  {
    if (currentMillis - Button_0_Millis >=  500)
    {
      digitalWrite(2, LOW);
      Button_0_Flag = 1;
      Button_0_Millis = millis();

    }
  }

  if ((Button_0_Pressed_Flag == 1) && (Button_0_Flag == 1))
  {
    if (currentMillis - Button_0_Millis >=  500)
    {
      digitalWrite(2, HIGH);
      Button_0_Flag = 0;
      Button_0_Millis = millis();
    }
  }
}

//============================================================
void Button_1()
{
  if (Button_1_Pressed_Flag == 1)
  {
    if (Button_1_Flag == 0)
    {
      delay(40);
      Serial.println(Pin_1_val);
      Pin_1_val += 5;
      analogWrite(3, Pin_1_val);
      if (Pin_1_val >= 255)
      {
        Button_1_Flag = 1;
      }
    }
    else
    {

      dealay(40);
      Serial.println(Pin_1_val);
      Pin_1_val -= 5;
      analogWrite(3, Pin_1_val);
      if (Pin_1_val <= 0)
      {
        Button_1_Flag = 0;
      }
    }
  }
}
//=============================================================
void Button_Down()
{
  if ((Button_4_Pressed_Flag == 1) && (Button_Down_Flag == 1))
  {
    if (Light_Setting > 0)
    {
      delay(25);
      Light_Setting--;
      Serial.println(Light_Setting);
      Serial.println(Button_4_Pressed_Flag);
      if (Light_Setting <= 0)
      {
        Button_Down_Flag = 0;
        ;
      }
      analogWrite(6, Light_Setting);
    }
  }
}

//===========================================================
void Button_Up()
{
  if ((Button_4_Pressed_Flag == 1) && (Button_Up_Flag == 1))
  {
    if (Light_Setting < 255)
    {
      delay(25);
      Light_Setting++;
      Serial.println(Light_Setting);
      Serial.println(Button_4_Pressed_Flag);
      if (Light_Setting >= 255)
      {
        Button_Up_Flag = 0;
        ;
      }
      analogWrite(6, Light_Setting);
    }
  }
}

//==============================================================

When the code for button 1 (0xFF30CF) is received, it sets the Button_1_Pressed_Flag and can then access the code in function Button_1(). Here in lies the problem. All the LED does is blink when Pin_1_val is >about 200.
If I change the analogWrites to pin 5, it works.
In case I had a bad connection or faulty gate, I ran the example “Fading” on Pin 3 it works.

Any ideas?

At 183 posts you must have seen:

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Very few volunteers will attempt helping you if partial code only is posted.

larryd
You are correct and I stand corrected. Thank you.
I have resubmitted the whole sketch, formatted, and added a little additional info.

Are you saying with your attached code:

analogWrite(3, Pin_1_val); does not work, but analogWrite(5, Pin_1_val); does work ?

Which little chinese keypads? We can't see what you see.

Any time you have numbers in your variable names or function names you should consider using arrays.

larryd
Yes. That is exactly what is going on.

I believe all Arduinos have pin D3 and D5 as PWM pins.

As a result, try a different Arduino to see if the problem remains.

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

Pin 3 on Uno (and its siblings) uses Timer2 for PWM.
IRremote uses Timer2 and disables PWM on pins 3 and 11.

oqibidipo:
Pin 3 on Uno (and its siblings) uses Timer2 for PWM.
IRremote uses Timer2 and disables PWM on pins 3 and 11.

+1 There you go.

See this library for NEC remotes that ‘does not’ use timers.

oqibidipo & larryd

Guys. Thanks. I had wondered if there might be any differences between the PWM pins, but could find no indication that this might be the case.

I am using a VS1838B, as supplied in the starter kit. Should be an easy enough change to the kit & sketch. (I hope)