Go Down

Topic: The setRGB function of shiftPWM is not working (Read 279 times) previous topic - next topic

aradarbel10

Hello, I am trying to use the shiftPWM library to control 8 RGBs with 3 595 chips.
The example code og the library works very good, but when trying to write my own code setRGB isn't working at all. non of the LEDs lights up.
Here is the code (ignore the shiftIn code, I commented it):
Code: [Select]

int inLatchPin = 3;
int inDataPin = 4;
int inClockPin = 2;

int colorData[8][3] = {
  {0, 0, 255},
  {0, 255, 0},
  {255, 0, 0},
  {255, 0, 255},
  {255, 255, 0},
  {0, 255, 255},
  {155, 155, 155},
  {255, 255, 255}
};

byte switchVar1 = 72;

//ShiftPWM_Library_Stuff
const int ShiftPWM_latchPin = 12;
#define SHIFTPWM_NOSPI
const int ShiftPWM_dataPin = 8;
const int ShiftPWM_clockPin = 13;
const bool ShiftPWM_invertOutputs = true;
const bool ShiftPWM_balanceLoad = false;
#include <ShiftPWM.h>
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 3;
int numRGBleds = numRegisters*8/3;

void setup() {
  Serial.begin(9600);
 
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.SetPinGrouping(1);
  ShiftPWM.Start(pwmFrequency,maxBrightness);

  pinMode(inLatchPin, OUTPUT);
  pinMode(inClockPin, OUTPUT);
  pinMode(inDataPin, INPUT);
}

void loop() {
  //shift in
  /*
  digitalWrite(inLatchPin, HIGH);
  digitalWrite(inLatchPin, LOW);

  switchVar1 = shiftIn(inDataPin, inClockPin);
  Serial.println(switchVar1, BIN);
  Serial.println("-------------------");
  */
  //LED control
  for(int i = 0; i < numRGBleds; i++){
    ShiftPWM.SetRGB(i, colorData[i][0], colorData[i][1], colorData[i][2]);
  }
}


Do you know what is wrong with it?

Thanks for ANY help,
Arad AKA Unlucky-man ;D

Grumpy_Mike

Quote
Do you know what is wrong with it?
Well you don't seem to stop a short time to allow you to see the display.

Try:-
Code: [Select]
for(int i = 0; i < numRGBleds; i++){
    ShiftPWM.SetRGB(i, colorData[i][0], colorData[i][1], colorData[i][2]);
  }
delay(300);
}

aradarbel10

Well you don't seem to stop a short time to allow you to see the display.
Hi Grumpy_Mike, And thank you for the response.
It looks like the delay is not the problem. I tried a delay up to 2 seconds and it didn't work...

Also, I am planning to use a display in the future (1.44" TFT LCD ili9163c) so I think I will need a fast loop.
Do you have any Idea?

aradarbel10

Forget it, Problem solved.
Looks like my wiring skills aren't the best...
I didn't figure out what was the problem yet, but after rewiring EVERYTHING on the breadboard it actually worked.
tho now I have a new problem: I am using common anode LEDs and looks like when I am trying to lower the max brightness variable it doesn't work with invertOutputs set to true.

Grumpy_Mike

Quote
looks like when I am trying to lower the max brightness variable it doesn't work
So have you tried to increase the value to get it lower?

This sounds like a problem with how the libiary is written.

aradarbel10

So have you tried to increase the value to get it lower?
No I didn't, I think I will just remap the valeus by myself in the code.

Go Up