Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
09.02.2010 at 19:33:31
News: Server upgrade went fine, you are now at the new system


Pages: 1 2 3 4 ... 6
Library for ShiftBrite (Read 23143 times)
macegr
God Member
*****
Offline

Arduino Ninja

Posts: 689

Re: Library for ShiftBrite
Reply #15 - 21.10.2008 at 22:24:30
 
mikalhart, that did the trick. I had already tried commenting out everything except the round()!  Huh

Thanks!
Back to top
 
 
View Profile | WWW   IP Logged
chippey
Junior Member
**
Offline

Arduino rocks

Posts: 59

Re: Library for ShiftBrite
Reply #16 - 22.10.2008 at 02:35:57
 
@macegr

Yeah, I got that same error too.  I found a fix(es) though.  0012 somehow doesn't like the  include of wiring.h (even though it looks like wiring.h should be able to handle it), and also doesn't like uint16_t in the 5bit luts, so I changed that too.

I'll post a zip file soon with the changes after I clean things up a bit.  I'm also toying with a new version of the library to handle long chains of ShiftBrites more effectively and in a more sensible way.  Still trying to figure out what that more sensible way is though, and how best to do it  Roll Eyes

edit:  Heh, just saw mikalhart's reply.  Looks like there's more than one solution.  Off to tweak more code! Cheesy
Back to top
 
 
View Profile   IP Logged
Japala
YaBB Newbies
*
Offline

Arduino rocks

Posts: 2

Re: Library for ShiftBrite
Reply #17 - 07.01.2009 at 23:17:37
 
Any progress on this?
Back to top
 
 
View Profile   IP Logged
blustang
YaBB Newbies
*
Offline

Arduino rocks

Posts: 20

Re: Library for ShiftBrite
Reply #18 - 08.01.2009 at 07:03:41
 
Hello I to would like to check on the progress of this.  I also am having problems getting the library to work.  I keep getting the Wprogram.h error and i am to much of a newbie to fix it.   any help would be appreciated
Back to top
 
 
View Profile   IP Logged
mikalhart
God Member
*****
Offline

Arduino rocks

Posts: 940
Austin, TX USA
Re: Library for ShiftBrite
Reply #19 - 08.01.2009 at 07:25:32
 
I have found that adding the following sequence immediately after the last #include <libraryname.n> line in your sketch resolves the Arduino 0012 library incompatibility problem in most cases.  (If it doesn't, let me know what the error message is.)

Code:
#undef int
#undef char
#undef long
#undef byte
#undef abs
#undef float
#undef round 



Mikal
Back to top
 
 
View Profile   IP Logged
blustang
YaBB Newbies
*
Offline

Arduino rocks

Posts: 20

Re: Library for ShiftBrite
Reply #20 - 08.01.2009 at 08:56:07
 
That did the trick!!!  Your the greatest!!!


I have the 4 SB's(soon to be 15-20 if i can get it to work) lighting up sequentially in this pattern

1
1 1
1 1 1
1 1 1 1
  1 1 1
     1 1
        1
     1 1
  1 1 1
1 1 1 1
1 1 1
1 1
1

every time the next light in the chain lights all the SB's flicker.  I have to say it is a neat look (will post a video if i have time)  but I was hoping for something more smooth any suggestions
Back to top
 
 
View Profile   IP Logged
blustang
YaBB Newbies
*
Offline

Arduino rocks

Posts: 20

Re: Library for ShiftBrite
Reply #21 - 08.01.2009 at 09:02:43
 
Here is what i have

Code:
#include "ShiftBrite.h"
#undef int
#undef char
#undef long
#undef byte
#undef abs
#undef float
#undef round


ShiftBrite SB(10); //A ShiftBrite starting on pin 10, assumes the next pins are sequentially going up

void setup() {
  pinMode(9,OUTPUT);
  digitalWrite(9,HIGH);
  SB.setPower(127);
}


//This examples has 4 ShiftBrites chained together in series, and cycles some colours through them
void loop() {
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  SB.setColor(0,0,1023);
  delay(100);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  delay(100);
  SB.setColor(0,0,0);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  delay(100);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  delay(100);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,0);
  delay(100);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  delay(100);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  delay(100);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  delay(100);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,0);
  delay(100);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  delay(100);
  SB.setColor(0,0,0);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  delay(100);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  SB.setColor(0,0,1023);
  SB.setColor(0,0,1023);
  delay(100);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  SB.setColor(0,0,0);
  SB.setColor(0,0,1023);
  delay(100);
}
 

Back to top
 
 
View Profile   IP Logged
blustang
YaBB Newbies
*
Offline

Arduino rocks

Posts: 20

Re: Library for ShiftBrite
Reply #22 - 09.01.2009 at 00:19:12
 
Back to top
 
 
View Profile   IP Logged
macegr
God Member
*****
Offline

Arduino Ninja

Posts: 689

Re: Library for ShiftBrite
Reply #23 - 09.01.2009 at 02:30:52
 
The reason for the flicker is because this library latches the ShiftBrites every time you set a color. That means it's pushing the lights down the chain visibly. I don't actually use this library, preferring to use a hardware SPI function in the main sketch instead.

If chippey moved the latch pulse out of the .setcolor command and into a .latch command, then you could output all the colors and then hit the latch when you're done. It would then change all the ShiftBrites to their new colors at the same instant.

I'll come back in here after a while and post the functions I'm currently using, though they aren't in a library.
Back to top
 
 
View Profile | WWW   IP Logged
blustang
YaBB Newbies
*
Offline

Arduino rocks

Posts: 20

Re: Library for ShiftBrite
Reply #24 - 09.01.2009 at 04:27:20
 
will be looking forward to your reply
Back to top
 
 
View Profile   IP Logged
blustang
YaBB Newbies
*
Offline

Arduino rocks

Posts: 20

Re: Library for ShiftBrite
Reply #25 - 10.01.2009 at 04:56:21
 
macegr

the above code through out a  error at:

void SB_SendPacket() {

   if (SB_CommandMode == B01) {
    SB_RedCommand = 127;
    SB_GreenCommand = 127;
    SB_BlueCommand = 127;
   }

In function 'void SB_SendPacket ()':
error: 'SB_CommandMode' was not declared in this scope In function 'void WriteLEDArray()':

thanks for the help  I am still trying to understand every thing.  This is the only thing i will probably ever program.  so i am trying to figure out how to do thing without trying to learn every thing else  which is more difficult then i thought it would be


Back to top
 
 
View Profile   IP Logged
macegr
God Member
*****
Offline

Arduino Ninja

Posts: 689

Re: Library for ShiftBrite
Reply #26 - 10.01.2009 at 06:50:59
 
Yes, I didn't actually test that code since I didn't have a setup ready...doing that now, so I'll edit that listing soon.

Edit: here's the updated code for the simple effect. Variable declarations were missing.

Code:
#define clockpin 13 // DI
#define enablepin 10 // LI
#define latchpin 9 // EI
#define datapin 11 // CI

#define NumLEDs 5

int LEDChannels[NumLEDs][3] = {0};
int SB_CommandMode;
int SB_RedCommand;
int SB_GreenCommand;
int SB_BlueCommand;

void setup() {

   pinMode(datapin, OUTPUT);
   pinMode(latchpin, OUTPUT);
   pinMode(enablepin, OUTPUT);
   pinMode(clockpin, OUTPUT);
   SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0);
   digitalWrite(latchpin, LOW);
   digitalWrite(enablepin, LOW);


}

void SB_SendPacket() {

    if (SB_CommandMode == B01) {
     SB_RedCommand = 127;
     SB_GreenCommand = 127;
     SB_BlueCommand = 127;
    }

    SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4;
    while(!(SPSR & (1<<SPIF)));
    SPDR = SB_BlueCommand<<4 | SB_RedCommand>>6;
    while(!(SPSR & (1<<SPIF)));
    SPDR = SB_RedCommand << 2 | SB_GreenCommand>>8;
    while(!(SPSR & (1<<SPIF)));
    SPDR = SB_GreenCommand;
    while(!(SPSR & (1<<SPIF)));

}

void WriteLEDArray() {

    SB_CommandMode = B00; // Write to PWM control registers
    for (int h = 0;h<NumLEDs;h++) {
	  SB_RedCommand = LEDChannels[h][0];
	  SB_GreenCommand = LEDChannels[h][1];
	  SB_BlueCommand = LEDChannels[h][2];
	  SB_SendPacket();
    }

    delayMicroseconds(15);
    digitalWrite(latchpin,HIGH); // latch data into registers
    delayMicroseconds(15);
    digitalWrite(latchpin,LOW);

    SB_CommandMode = B01; // Write to current control registers
    for (int z = 0; z < NumLEDs; z++) SB_SendPacket();
    delayMicroseconds(15);
    digitalWrite(latchpin,HIGH); // latch data into registers
    delayMicroseconds(15);
    digitalWrite(latchpin,LOW);

}

void loop() {

   LEDChannels[0][0] = 1023;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;

   LEDChannels[4][0] = 0;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 1023;

   WriteLEDArray();
   delay(200);

   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 1023;

   LEDChannels[4][0] = 1023;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;

   WriteLEDArray();
   delay(200);



}
 

Back to top
 
« Last Edit: 10.01.2009 at 13:26:21 by macegr »  
View Profile | WWW   IP Logged
macegr
God Member
*****
Offline

Arduino Ninja

Posts: 689

Re: Library for ShiftBrite
Reply #27 - 10.01.2009 at 13:35:09
 
Aaaand I also wrote code to do the whole 2008 KITT scanner effect. It works with ShiftBrite chains of any length divisible by two. Any solid or mixed color can be set as the base color, and the gradient at the beginning and end of the main lit section can be tweaked and resized. The speed and direction can be selected. Below is a YouTube video of the effect (running my old Shifty VU's, total of 20 ShiftBrites), and all the code. Please take note of the pins I have selected at the beginning of the code, and match them to the first ShiftBrite.

The code is kind of lashed together and there are probably a lot of possible optimizations, but it works.



#define clockpin 13 // DI
#define enablepin 10 // LI
#define latchpin 9 // EI
#define datapin 11 // CI

#define NumLEDs 16
#define CenterWidth 8

int LEDChannels[NumLEDs * 2][3] = {0};
int SB_CommandMode;
int SB_RedCommand;
int SB_GreenCommand;
int SB_BlueCommand;

// these are small so i'll leave them in RAM, larger data should be moved to PROGMEM
int KittLeadingEdge[] = {600, 400, 200};
int KittTrailingEdge[] = {200, 400, 600};

int KittLeadSize = sizeof(KittLeadingEdge) / sizeof(int);
int KittTrailSize = sizeof(KittTrailingEdge) / sizeof(int);
int KittTotalSize = KittLeadSize + KittTrailSize + CenterWidth;

void setup() {

  pinMode(datapin, OUTPUT);
  pinMode(latchpin, OUTPUT);
  pinMode(enablepin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0);
  digitalWrite(latchpin, LOW);
  digitalWrite(enablepin, LOW);


}

void SB_SendPacket() {

   if (SB_CommandMode == B01) {
    SB_RedCommand = 127;
    SB_GreenCommand = 127;
    SB_BlueCommand = 127;
   }

   SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4;
   while(!(SPSR & (1<<SPIF)));
   SPDR = SB_BlueCommand<<4 | SB_RedCommand>>6;
   while(!(SPSR & (1<<SPIF)));
   SPDR = SB_RedCommand << 2 | SB_GreenCommand>>8;
   while(!(SPSR & (1<<SPIF)));
   SPDR = SB_GreenCommand;
   while(!(SPSR & (1<<SPIF)));

}

void WriteLEDArray() {

   SB_CommandMode = B00; // Write to PWM control registers
   for (int h = 0;h<NumLEDs*2;h++) {
       SB_RedCommand = LEDChannels[h][0];
       SB_GreenCommand = LEDChannels[h][1];
       SB_BlueCommand = LEDChannels[h][2];
       SB_SendPacket();
   }

   delayMicroseconds(15);
   digitalWrite(latchpin,HIGH); // latch data into registers
   delayMicroseconds(15);
   digitalWrite(latchpin,LOW);

   SB_CommandMode = B01; // Write to current control registers
   for (int z = 0; z < NumLEDs*2; z++) SB_SendPacket();
   delayMicroseconds(15);
   digitalWrite(latchpin,HIGH); // latch data into registers
   delayMicroseconds(15);
   digitalWrite(latchpin,LOW);

}

// Re-use my old array rotating code, but use collapsed fake array to save memory
// (at expense of CPU)
int KittFakeArray(int index) {

 if (index >= 0 && index < KittTrailSize) {
     return KittTrailingEdge[index];
 } else if (index >= KittTrailSize && index < (CenterWidth + KittTrailSize)) {
     return 1023;
 } else if (index >= (CenterWidth + KittTrailSize) && index < KittTotalSize) {
     return KittLeadingEdge[index-CenterWidth-KittTrailSize];
 } else {
     return 0;
 }
 
}
 

void NewKittFill(int dir, int FillSpeed, int FadeSteps, int red, int green, int blue) {

 int KittFadeFactor = 0;
 int revIndex;
 
 
 for (int FillCount = 0; FillCount < (KittTotalSize+NumLEDs); FillCount++) {
 
   for (int FadeCount = 0; FadeCount < FadeSteps; FadeCount++) {
   
     for (int i = 0; i < NumLEDs; i++) {
       
       KittFadeFactor = ((KittFakeArray(KittTotalSize - FillCount + i)) * (FadeSteps - FadeCount - 1) + (KittFakeArray(KittTotalSize - FillCount - 1 + i)) * (FadeCount)) / (2 * FadeSteps);

       if (dir == 0) {

         LEDChannels[i][0] = (long) red * KittFadeFactor / 1023;
         LEDChannels[i][1] = (long) green * KittFadeFactor / 1023;
         LEDChannels[i][2] = (long) blue * KittFadeFactor / 1023;

         revIndex = NumLEDs * 2 - i - 1;
         
         LEDChannels[revIndex][0] = LEDChannels[i][0];
         LEDChannels[revIndex][1] = LEDChannels[i][1];
         LEDChannels[revIndex][2] = LEDChannels[i][2];
       } else {
         
         revIndex = NumLEDs - 1 - i;
         
         LEDChannels[revIndex][0] = (long) red * KittFadeFactor / 1023;
         LEDChannels[revIndex][1] = (long) green * KittFadeFactor / 1023;
         LEDChannels[revIndex][2] = (long) blue * KittFadeFactor / 1023;


         LEDChannels[NumLEDs + i][0] = LEDChannels[revIndex][0];
         LEDChannels[NumLEDs + i][1] = LEDChannels[revIndex][1];
         LEDChannels[NumLEDs + i][2] = LEDChannels[revIndex][2];
       }
   
     }
   
     WriteLEDArray();
     delay(FillSpeed);
   
   }
   
 }
 
}

void loop() {

 for (int cycles = 1; cycles < 10; cycles++) {
 
   NewKittFill(0, 12, 8, 1023, 0, 0);
   delay(200);
   NewKittFill(1, 10, 7, 1023, 0, 0);
   delay(200);

 }

 NewKittFill(0, 10, 7, 0, 1023, 0);
 delay(300);
 NewKittFill(1, 10, 7, 0, 1023, 0);
 delay(300);
 
 NewKittFill(0, 10, 7, 0, 0, 1023);
 delay(300);
 NewKittFill(1, 10, 7, 0, 0, 1023);
 delay(300);

 NewKittFill(0, 10, 7, 800, 0, 1023);
 delay(300);
 NewKittFill(1, 10, 7, 800, 0, 1023);
 delay(300);

 NewKittFill(0, 10, 7, 200, 0, 0);
 delay(300);
 NewKittFill(1, 10, 7, 200, 0, 0);
 delay(300);
 
}

Back to top
 
« Last Edit: 11.01.2009 at 06:14:56 by macegr »  
View Profile | WWW   IP Logged
blustang
YaBB Newbies
*
Offline

Arduino rocks

Posts: 20

Re: Library for ShiftBrite
Reply #28 - 11.01.2009 at 03:11:28
 
Grin   OOOOHHHHH Cheesy   gooddyy Smiley



Thanks for this!!!!     I am getting ready to jump over and buy 50 ofthe  SBs.  I am just trying to figure if i should buy headerless.   I want to tie them together side buy side and fit the whole string in a 1.00"OD x .875 ID  lexan square tube.  I think the best why for me to do that is to get headerless SBs and fit one side with right angle male headers and bend the tips up to fit to the next SB and just solder it directly.  I was looking for female right angle headers but there hard to find and i think they might have to large of a gaps between the SBs.   I want to get them as tight as possible.  

any suggestions
Back to top
 
 
View Profile   IP Logged
macegr
God Member
*****
Offline

Arduino Ninja

Posts: 689

Re: Library for ShiftBrite
Reply #29 - 11.01.2009 at 03:54:41
 
Maybe you could chain headerless ShiftBrites by overlapping them and soldering in pins or wires, like so:


But I actually don't like the idea. It would be very hard to desolder without damaging surrounding devices, if you needed to replace a pixel.

Instead, you could use these in a similar way to how you were thinking of using square pin headers, side by side instead of overlapping: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=923345-02-N...



You'd need two packs, so $22 for all the jumpers. And a lot of soldering...about 600 joints. But if you have the patience, you'll end up with chains that are still a little flexible, and you can snip the jumper wires for easy desoldering if you ever need to replace a device.
Back to top
 
 
View Profile | WWW   IP Logged
Pages: 1 2 3 4 ... 6