PWM Shift Registers

Hi, I understand PWM and stuff but am a bit of a noob with this,

i understand shift registers using the 595 currently,

My project is to be able to get 8 seperate RGB leds pwm so i can get red, orange/yellow, green, cyan, blue, magenta and whiteish.

Is this possible with the arduino and shift registers, so each RGB led can be controlled seperat form the rest. :o

Many thanks Andy :slight_smile:
[smiley=dankk2.gif]

Andy, if you want more PWM outputs then have a look at this: Arduino Playground - TLC5940

@andyC, mem's advice is the right way to go...

The 595's can only give you one output state: on/off. For multiplexed PWM you need a special chip like the one mentioned.

D

AH OK Thanks for the swift replies i have requested some samples and cant wait for them to arrive,

Is it possible to control say just 1 output pin at a time and produce a sine wave effect?

Thanks

Andy

P.S before discovering Arduino i used the picaxe system great for learning basic stuff this arduino is amazing :smiley:

what do u mean "samples", did you for free or sumthin?

Is it possible to control say just 1 output pin at a time and produce a sine wave effect?

There is arduino pwm sine wave code table here: http://www.arduino.cc/playground/Main/PWMallPins

what do u mean "samples", did you for free or sumthin?

Most of the semi companies will send samples for free... but it takes time.

Maxim and Microchip are always good for three of each chip, you just have to register on their site.

D

what do u mean "samples", did you for free or sumthin?

Start your journey into component samples here.

--Phil.

Hey all,

change of plan, 3 595s one for each colour RGB Bit of code and hey got 6 colours :stuck_out_tongue: now need a bit of help thou, got say the first 6 leds lit up 1,2,3,4,5,6 no problem, how do i move that sequence along to light leds 2,3,4,5,6,7 as a running effect?

Thanks Andy

Sorry here is the modified code :slight_smile:

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

//holders for infromation you're going to pass to shifting function
byte dataRED;
byte dataGREEN;
byte dataBLUE;
byte dataArrayRED[3];
byte dataArrayGREEN[3];
byte dataArrayBLUE[3];

void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
Serial.begin(9600);

//Arduino doesn't seem to have a way to write binary straight into the code
//so these values are in HEX. Decimal would have been fine, too.

dataArrayRED[0] = 0xC4; //11111110
dataArrayGREEN[1] = 0x70; //0110000
dataArrayBLUE[2] = 0x1C; //11000000

//function that blinks all the LEDs
//gets passed the number of blinks and the pause time
blinkAll(0,10);
}

void loop() {

blinkAll(0,00);
for (int j = 0; j < 3; j++) {
//load the light sequence you want from array
dataBLUE = dataArrayBLUE[j];
dataGREEN = dataArrayGREEN[j];
dataRED = dataArrayRED[j];

//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, dataBLUE);
shiftOut(dataPin, clockPin, dataGREEN);
shiftOut(dataPin, clockPin, dataRED);

//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(1);
}
}

// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low

//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);

//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);

//for each bit in the byte myDataOut?
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);

//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}

//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}

//stop shifting
digitalWrite(myClockPin, 0);
}

//blinks the whole register based on the number of times you want to
//blink "n" and the pause between them "d"
//starts with a moment of darkness to make sure the first blink
//has its full visual effect.
void blinkAll(int n, int d) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
delay(0);
for (int x = 0; x < n; x++) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 255);
digitalWrite(latchPin, 1);
delay(d);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
delay(d);
}