Controlling LED dimming with an IR sensor, not dimming

Good day, I am fairly new to the Arduino world, and as I am working through different projects and tutorials I am trying to add them together, to create new projects. What I am trying to do right now is control 8 LED’s connected through a shift register; these are being controlled by a remote control through IR signals.
I can control and choose which LED I want lite by using either the CH+, CH-, or num pad on the remote. However, I want to be able to control the brightness of the LED’s by using Vol+ & Vol-. The code that I am using is attache below:

//Shift register setup
int LatchPin = 5;
int ClockPin = 6;
int DataPin = 4;
int OutputPin = 3;
byte Leds = 0;
//byte bright;

//IR sensor setup
#include "IRremote.h"
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

//System setup
int Brightness = 10;
int Power = 0;
int Led = 0;

void setup() {
  pinMode(LatchPin, OUTPUT);
  pinMode(DataPin, OUTPUT);
  pinMode(ClockPin, OUTPUT);
  pinMode(OutputPin, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  analogWrite(OutputPin, Brightness);
  //setBrightness(Brightness);
  Leds = 0;
  if (irrecv.decode(&results)) {
    RemoteIR();
    Leds = 0;
    bitSet(Leds, Led);
    updateShiftRegister();
    analogWrite(OutputPin, Brightness);
    //setBrightness(Brightness);
    Serial.println(results.value);
    Serial.println("-----This is a test of variables-----");
    Serial.print("Power level: ");
    Serial.println(Power);
    Serial.print("Brightness level: ");
    Serial.println(Brightness);
    Serial.print("Choosen LED: ");
    Serial.println(Led);
    irrecv.resume(); // Receive the next value
  }
}
void updateShiftRegister()
{
  digitalWrite(LatchPin, LOW);
  shiftOut(DataPin, ClockPin, LSBFIRST, Leds);
  digitalWrite(LatchPin, HIGH);
}
void setBrightness(int B)
{
  analogWrite(OutputPin, B);
}

int RemoteIR() {
  Serial.println("-----Inside Function-----");
  Serial.print("Inside variable Power: ");
  Serial.println(Power);
  Serial.print("Inside variable Brightness: ");
  Serial.println(Brightness);
  switch(results.value)
  {
    case 2464125561:
      return Led = 1;
      break;      
    case 2278412527:
      return Led = 2;
      break;      
    case 930645859:
      return Led = 3;
      break;
    case 2769913147:
      return Led = 4;
      break;
    case 1558024125:
      return Led = 5;
      break;
    case 4382025:
      return Led = 6;
      break;
    case 834338975:
      return Led = 7;
      break;
    case 356487335:
      return Led = 8;
      break;
    case 1752348172:
      return Led = 9;
      break;
    case 1851193636:
      return Led = 0;
      break;    
    case 145127458:
      if (Led < 7)
        return ++Led;
      if (Led == 7)
        return Led = 0;
      break;
    case 4222411808:
      if (Led > 0)
        return --Led;
      if (Led == 0)
        return Led = 7;
      break;
    case 1936644142:
      if (Power == 0)
        Power =1;
      else
        Power = 0;
      break;
    case 551502015:
      return Brightness = Brightness + 10;
      //analogWrite(OutputPin, Brightness);
      break;
    case 551534655:
      return Brightness = Brightness - 10;
      //analogWrite(OutputPin, Brightness);
      break;
    default:
      Serial.println("ERROR!");
      break;
  }
}

Part of this code comes from an adafruit tutorial:

When I run there code as they present it, it does work fine. They all light up, and they all dim down.

I know I am stuck some where with the analogWrite() function. As you can see in the code, I have tried to call this directly in the main loop, as well as in the function SetBrightness().

DEBUGGING NOTES:
When I view the console, I can see that my Brightness variable is changing based on the Vol+ & Vol- buttons, but nothing changes on the board.

Parts:
74HC595
220 ohm resistors
8 LED’s

Any help would be greatly appreciated.

A couple of points:

You do not seem to have set bounds on “Brightness” You need to constrain it to be between 0 and 255.

Do not execute analogWrite in the raw main loop. You only execute it when you want to make a change in the brightness.

If that does not sort things out, we need a perfectly focussed (daylight but not direct sun) photo of your circuit and perhaps a schematic as well to check that you are actually doing what you think you are doing.

Thank you for the feedback. I have tried calling the analogwrite inside a function instead of the main loop, and I am still getting nothing.
However, while experimenting, I did find that if I increase the value of Brightness =>255 it turns the light off. But, if I decrease the value of Brightness =< 0, it does nothing; the light stays lite. To me that seems backwards.
How would I go about setting a limit on brightness? Is it basically just setting an IF statement to check the value?

Attached, is a schematic of the layout.

Paul

Yes that is what writing analogWrite values outside the limits does, it is perfectly normal if you think what is happening. The call only takes a single byte so numbers over 255 have to be in two bytes. The call is then only using the least significant byte of this number and the least significant byte of 256 is zero. The least significant byte of 257 is one and so on. This is called wrapping round and it will do it at 256 intervals. So the numbers from 256 to 511 will act exactly like the numbers 0 to 255.

Hi, you should have a 0.1uF bypass cap on your shift register, close to and accross it's power pins.

Your RemoteIR() function returns an int but you don't do anything with the result when you call it in loop(). You might as well make RemoteIR() void and get rid of all those return keywords inside the function. You haven't been consistent with use of return anyway, for example there is to return where you set power = 1. Can't see how this could stop the shift register updating, however.

Paul

PaulRB- How would you suggest I rewrite my RemoteIR()? I just re-wrote it as this:

case 551502015:
     return Brightness = Brightness + 10;
     //analogWrite(OutputPin, Brightness);
     break;
   case 551534655:
     return Brightness = Brightness - 10;
     //analogWrite(OutputPin, Brightness);
     break;

I am using the following in the main loop:

void loop() {
 //analogWrite(OutputPin, Brightness);
 setBrightness(Brightness);
 Leds = 0;
 if (irrecv.decode(&results)) {
   RemoteIR();
   Leds = 0;
   bitSet(Leds, Led);
   updateShiftRegister();
   //analogWrite(OutputPin, Brightness);
   setBrightness(Brightness);

What it should be doing is getting the brightness, either increaseing or decreasing it by 10, and then putting it into setBrightness().

Another issue, that may be causing all of this. When I declare my variables at the top top, I have Brightness = 10. I would suspect that this should make my LED very dim, as there should be very little power signal going to it. However, it still is lite the same intensity as if i had it set at 255.

//Shift register setup
int LatchPin = 5;
int ClockPin = 6;
int DataPin = 4;
int OutputPin = 3;
byte Leds = 0;
//byte bright;

//IR sensor setup
#include "IRremote.h"
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

//System setup
int Brightness = 10;
int Power = 0;
int Led = 0;

The OE pin on 74hc595 is "active-low" meaning the shift register's outputs are enabled when OE is LOW (0V). If you look at the data sheet, or any accurate schematic drawing application, you can see it is shown with a line drawn above the letters OE. The line means "not", logically speaking. Therefore analogWrite(pin, 255) means the outputs are off and analogWrite(pin, 0) means outputs are fully on/bright. So analogWrite(pin, 10) would be almost full brightness.

Ok, I understand what you are saying about the “active-low”. That is something that i completly overlooked when reading different tutorials, and trying to learn. However, even when I think I correct it, I am still not getting the desired results.
So I went and changed my SetBrightness() function:

void setBrightness(int B)
{
  analogWrite(OutputPin, 255-B);
}

Now, from what you describe it should take what would normally be a full power and reverse it. So if I passed it a 10 it would be 255-10 = 245. It may be more complicated then it needs, but is that the correct thinking?

I also went back, and found this code, which is what I am trying to build off of:

int LatchPin = 5;
int ClockPin = 6;
int DataPin = 4;
int OutputEnablePin = 3;
int LedTest = 10;

byte Leds = 0;
void setup() {
  // put your setup code here, to run once:
pinMode(LatchPin, OUTPUT);
pinMode(DataPin, OUTPUT);
pinMode(ClockPin, OUTPUT);
pinMode(OutputEnablePin, OUTPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  setBrightness(10);
  Leds = 0;
  //updateShiftRegister();
  //delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(Leds, i);
    updateShiftRegister();
    delay(100);
  }
  for (int b = 255; b > 0; b--)
  {
    //Serial.print("Byte Brightness: ");
    //Serial.println(b);
    setBrightness(b);
    delay(30);
  }
}
void updateShiftRegister()
{
  digitalWrite(LatchPin, LOW);
  shiftOut(DataPin, ClockPin, LSBFIRST, Leds);
  digitalWrite(LatchPin, HIGH);
}
void setBrightness(int brightness)
{
  analogWrite(OutputEnablePin, 255-brightness);
}

This will light up all the LED’s in sequence, then dim them. This code works perfectly like it is suppose to. Since I used most of this code in my own example, what am I missing? Why will the above code change the power, but mine wont?
**NOTE: in the above code I did set the brightness at 10 in the first line of the main loop on purpose. This was to make sure that it would go from dim to bright and then down again.