Submitted by Andrew (not verified) on Sat, 06/28/2008 - 08:01.
See if you can make heads or tails of this. Not the most efficient or well documented but does the job and is easy to expand with differnt effects etc. just make a now function and call it from loop.
int datapin = 10; // DI
int latchpin = 11; // LI
int enablepin = 12; // EI
int clockpin = 13; // CI
int chainLength = 4; //Number of ShiftBrites in chain
int image[4][3]; //R,G,B for each ShiftBrite in the chain, first element is No. of SB's in chain
unsigned long SB_CommandPacket;
int SB_CommandMode;
int SB_BlueCommand;
int SB_RedCommand;
int SB_GreenCommand;
SB_CommandMode = B01; // Write to current control registers
SB_RedCommand = 127; // Full current
SB_GreenCommand = 127; // Full current
SB_BlueCommand = 127; // Full current
for (int i=0; i < chainLength; i++) {
SB_SendPacket(); //Send current setup packet to every ShiftBrite
image[i][0] = 0; //Set red to 0
image[i][1] = 0; //Set green to 0
image[i][2] = 0; //Set blue to 0
}
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,HIGH); // latch data into registers
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,LOW);
}
for (int x=0; x < chainLength; x++) {
SB_CommandMode = B00; // Write to PWM control registers
SB_RedCommand = image[x][0];
SB_GreenCommand = image[x][1];
SB_BlueCommand = image[x][2];
SB_SendPacket();
}
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,HIGH); // latch data into registers
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,LOW);
}
void loop() {
chase();
}
void chase() {
for (int i=0; i < chainLength; i++) {
image[i][1] = 100; //Set new to max
if(i != 0){
image[(i-1)][1] = 0; //Set last to min
}
SB_SendImage();
delay(100);
}
image[(chainLength - 1)][1] = 0;
SB_SendImage();
}
See if you can make heads or
See if you can make heads or tails of this. Not the most efficient or well documented but does the job and is easy to expand with differnt effects etc. just make a now function and call it from loop.
int datapin = 10; // DI
int latchpin = 11; // LI
int enablepin = 12; // EI
int clockpin = 13; // CI
int chainLength = 4; //Number of ShiftBrites in chain
int image[4][3]; //R,G,B for each ShiftBrite in the chain, first element is No. of SB's in chain
unsigned long SB_CommandPacket;
int SB_CommandMode;
int SB_BlueCommand;
int SB_RedCommand;
int SB_GreenCommand;
void setup() {
pinMode(datapin, OUTPUT);
pinMode(latchpin, OUTPUT);
pinMode(enablepin, OUTPUT);
pinMode(clockpin, OUTPUT);
digitalWrite(latchpin, LOW);
digitalWrite(enablepin, LOW);
SB_CommandMode = B01; // Write to current control registers
SB_RedCommand = 127; // Full current
SB_GreenCommand = 127; // Full current
SB_BlueCommand = 127; // Full current
for (int i=0; i < chainLength; i++) {
SB_SendPacket(); //Send current setup packet to every ShiftBrite
image[i][0] = 0; //Set red to 0
image[i][1] = 0; //Set green to 0
image[i][2] = 0; //Set blue to 0
}
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,HIGH); // latch data into registers
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,LOW);
}
void SB_SendPacket() {
//Build Packet
SB_CommandPacket = SB_CommandMode & B11;
SB_CommandPacket = (SB_CommandPacket << 10) | (SB_BlueCommand & 1023);
SB_CommandPacket = (SB_CommandPacket << 10) | (SB_RedCommand & 1023);
SB_CommandPacket = (SB_CommandPacket << 10) | (SB_GreenCommand & 1023);
//Send packet
shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 24);
shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 16);
shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 8);
shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket);
}
void SB_SendImage() {
for (int x=0; x < chainLength; x++) {
SB_CommandMode = B00; // Write to PWM control registers
SB_RedCommand = image[x][0];
SB_GreenCommand = image[x][1];
SB_BlueCommand = image[x][2];
SB_SendPacket();
}
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,HIGH); // latch data into registers
delay(1); // adjustment may be necessary depending on chain length
digitalWrite(latchpin,LOW);
}
void loop() {
chase();
}
void chase() {
for (int i=0; i < chainLength; i++) {
image[i][1] = 100; //Set new to max
if(i != 0){
image[(i-1)][1] = 0; //Set last to min
}
SB_SendImage();
delay(100);
}
image[(chainLength - 1)][1] = 0;
SB_SendImage();
}