Pages: [1] 2 3   Go Down
Author Topic: Similar to KITT light bar but not...I need help please  (Read 2822 times)
0 Members and 1 Guest are viewing this topic.
Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The project I am trying to complete is to have a set of shiftbrites (currently just 10) change from red to blue in sequence.

They need to all start out being RED then slowly change to BLUE but only 1 at a time as they work down the chain, and as it works down the chain the upper most LEDs will go out. Kind of hard to explain.
 
Basically I want to create the effect of a GAS (RED) being compressed to a liquid (BLUE) and make it look as if there is a "plunger" of some sort above it pushing it down (compressing it).

Ending at 2 LEDS showing bright BLUE with the plunger (white or black or brown..does not matter) sitting right above it.


I started with the code used for the ShiftBrite Knight Rider @ http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1217291822/27#27

The code change was easy to just get the red and blue but beyond that I'm lost.

I am new to this and have ordered 2 Arduino books as well as looking everywhere to learn.
All help greatly appreciated as this is a project for work they expect me to get done knowing I have never done this type of work before.

THANKS!
« Last Edit: August 08, 2011, 01:50:51 pm by ibourdon » Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is what I am trying to accomplish to difficult with this setup?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31395
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is what I am trying to accomplish to difficult with this setup?
A change in the setup is not going to make it any easier. You have two choices when it comes to sequences like this.

The first one is to work out what you need to do for every step and implement it problematically. So each step in the fade sequence needs to be created by some sort of algorithm.

The second one is to work out what you need to do for every step and implement it by means of a look up table, that is to say a pre defined array that you keep reading the values out of and sending to all the light modules.

It's not one of those things some one is going to write for you, you will have to learn how to program.
Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't necessarily want any one to write it for me but I would like a little guidance on how to write the code to control each individual shiftbrite module in the chain. Do I use a variation of shiftout() to identify each shiftbrite? How can I tell the 2nd shiftbrite to turn black while at the same time be telling the 9th & 10th shiftbrites to turn blue, while the ones inbetween stay red?

I guess I just need direction on how to implement this. I am new to this, though I do have some experience programming in c++.
« Last Edit: August 08, 2011, 06:50:26 pm by ibourdon » Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 10
Posts: 1235
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you check the code examples you can see that you don't even have to worry about how to tell each ShiftBrite to be a specific color. There's an array that holds all the RGB values and there's a WriteLEDArray() function that already does everything for you, when you want to update the actual LEDs with the contents array you have in memory. All you need to do is arbitrarily write any pixels with any colors you want, and then call the WriteLEDArray() function.
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help. I started with a basic sketch to get the colors to change how I need them. I have not simplified the code yet as I would like to get this to work exactly as needed before I try to condense the code.

Here is my code as of now ( WITHOUT LOOP() )...
Could some one guide me on adding a fade effect to the arrays I have so that the colors transition smoothly?

Code:
const int clockpin = 13; // DI
const int  enablepin = 10; // LI
const int latchpin = 9; // EI
const int datapin = 11; // CI

const int NumLEDs = 10; // Number of LEDs in chain
int fade = 64;
 
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 = 120;
     SB_GreenCommand = 100;
     SB_BlueCommand = 100;
    }
 
    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 Fade(int Steps)   //This is the start of fade code I was trying to write.
//{
//if (Steps >= 0) {
//   return 64[Steps];
// } else if (Steps <= 0) {
//  return 1023;
// }
//   else if (Steps >= 1023) {
//     return 0;
//   }
« Last Edit: August 15, 2011, 04:09:47 pm by ibourdon » Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the loop() section

Code:
void loop() {
 //1
   LEDChannels[0][0] = 1023;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 1023;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 1023;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 1023;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 1023;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 1023;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 1023;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 1023;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 1023;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 0;
 
   LEDChannels[9][0] = 1023;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 0;
 
   WriteLEDArray();
   delay(200);
  //2
   LEDChannels[0][0] = 200;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 500;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 700;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 1023;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 1023;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 1023;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 1023;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 1023;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 900;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 0;
 
   LEDChannels[9][0] = 900;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 0;
 
   WriteLEDArray();
   delay(200);
 //3 
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 200;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 500;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 700;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 1023;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 1023;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 1023;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 1023;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 900;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 0;
 
   LEDChannels[9][0] = 700;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 0;
 
   WriteLEDArray();
   delay(200);
//4   
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 0;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 200;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 500;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 700;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 900;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 900;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 800;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 700;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 00;
 
   LEDChannels[9][0] = 500;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 0;
 
   WriteLEDArray();
   delay(200);
//5   
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 0;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 0;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 200;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 500;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 700;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 700;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 700;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 500;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 0;
 
   LEDChannels[9][0] = 300;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 0;
 
   WriteLEDArray();
   delay(200);
   
//6   
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 0;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 0;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 0;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 200;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 500;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 500;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 300;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 200;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 0;
 
   LEDChannels[9][0] = 100;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 0;
 
   WriteLEDArray();
   delay(200);
//7   
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 0;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 0;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 0;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 0;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 200;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 300;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 200;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 100;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 0;
 
   LEDChannels[9][0] = 0;
   LEDChannels[9][1] = 250;
   LEDChannels[9][2] = 350;
 
   WriteLEDArray();
   delay(200);
 //8   
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 0;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 0;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 0;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 0;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 0;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 350;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 250;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 0;
   LEDChannels[8][1] = 250;
   LEDChannels[8][2] = 350;
 
   LEDChannels[9][0] = 0;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 800;
 
   WriteLEDArray();
   delay(200);
//9   
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 0;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 0;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 0;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 0;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 0;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 0;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 0;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 0;
   LEDChannels[8][1] = 300;
   LEDChannels[8][2] = 420;
 
   LEDChannels[9][0] = 0;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 1023;
 
   WriteLEDArray();
   delay(200);
//10
   LEDChannels[0][0] = 0;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 0;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
   
   LEDChannels[2][0] = 0;
   LEDChannels[2][1] = 0;
   LEDChannels[2][2] = 0;
 
   LEDChannels[3][0] = 0;
   LEDChannels[3][1] = 0;
   LEDChannels[3][2] = 0;
   
   LEDChannels[4][0] = 0;
   LEDChannels[4][1] = 0;
   LEDChannels[4][2] = 0;
 
   LEDChannels[5][0] = 0;
   LEDChannels[5][1] = 0;
   LEDChannels[5][2] = 0;
   
   LEDChannels[6][0] = 0;
   LEDChannels[6][1] = 0;
   LEDChannels[6][2] = 0;
 
   LEDChannels[7][0] = 0;
   LEDChannels[7][1] = 0;
   LEDChannels[7][2] = 0;
   
   LEDChannels[8][0] = 0;
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 1023;
 
   LEDChannels[9][0] = 0;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 1023;
 
   WriteLEDArray();
   delay(800);
}
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31395
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

See this for an example of how to do it:-
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253503406
Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the link, I have implemented the fadeall() function but still can't get that smooth transition. I will play with it. Thanks
Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't seem to get this to function, I keep getting:
fadetest.cpp: In function 'void loop()':
fadetest:102: error: invalid conversion from 'void (*)(int)' to 'int'

What am I doing wrong here?

Code:
void fade(int Steps)
{
  if (Steps >= 0)
  {
    Steps = 64;
  }
    else if (Steps <= 0)
    {
      Steps = 1023;
    }
      else if (Steps >= 1023)
      {
        Steps = 0;
      }
}

void loop() {
 
  //1
   LEDChannels[0][0] = fade;
   LEDChannels[0][1] = 0;
   LEDChannels[0][2] = 0;
 
   LEDChannels[1][0] = 1023;
   LEDChannels[1][1] = 0;
   LEDChannels[1][2] = 0;
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31395
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to post the bit of the code that gives the error. That is where you are trying to call that function.

It sounds like you are not using the right argument to pass to the function.
Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The most recent code I posted is giving me the error.

This line particularly:
LEDChannels[0][0] = fade;
LEDChannels[0][1] = 0;
LEDChannels[0][2] = 0;
...
...There are 10 LEDs worth of code, I just omitted all those..
...
WriteLEDArray();

fadetest.cpp: In function 'void loop()':
fadetest:102: error: invalid conversion from 'void (*)(int)' to 'int'

If I pass that line a variable, i.e..
LEDChannels[0][0] = fade(65);

The code will compile correctly but It does not fade..
Think I'm going about this a**backwards...
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31395
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well that last code you posted makes no sense at all.
1) You can't assign a function to a variable.
  so writing
LEDChannels[0][0] = fade(65);
simply sets LEDChannels[0][0] to the value returned by the fade function. The function is defined as void which means it doesn't return a value anyway.

2) That fade() function doesn't do anything anyway.

Quote
The code will compile correctly but It does not fade
That is because you are not doing any fading at all.

To fade you need to
1) write the brightness values into the LEDChannels array.
2) call the WriteLEDArray();
3) delay for some time to allow you to see that brightness
4) change the value and go back to 1

This needs to be in a loop that repeats until the fade is done.
« Last Edit: August 20, 2011, 03:49:17 am by Grumpy_Mike » Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well that makes sense. Thanks for the help. I will eventually figure it out.
Logged

Texas
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Lost in SPI FADE land
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still lost here and have been looking through every fade sketch I can find that involves shiftbrites.
I think its the SPI interface that is boggling me.

I have my sketch (without fading) setup how it needs to be. (Thanks to robtillaart & Grumpy_Mike)

But even looking at all the examples I have come across I don't know how to implement the fade as I need it.
yes I can make the shiftbrites fade to different colors but only all at once, not individually fade to different colors at the same time.

I know its nobody's job on here to do this for me but I'm stumped and have been with this part for a while now.
Here is the current code. (Which all fits in one post now, YAY!)
Code:
//LNG Lighting
const int clockpin = 13; // DI
const int  enablepin = 10; // LI
const int latchpin = 9; // EI
const int datapin = 11; // CI

const int NumLEDs = 10; // Number of LEDs in chain
 
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 = 120;
     SB_GreenCommand = 100;
     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() {
//1
   for (int i=0; i<10; i++)
   {
     LEDChannels[i][0] = 1023;
     LEDChannels[i][1] = 0;
     LEDChannels[i][2] = 0;
   }
   WriteLEDArray();
   delay(200);
//2   
   LEDChannels[0][0] = 200;
   LEDChannels[1][0] = 500;
   LEDChannels[2][0] = 700;
   LEDChannels[8][0] = 900;
   LEDChannels[9][0] = 900;

   WriteLEDArray();
   delay(200);
//3 
   LEDChannels[0][0] = 0;
   LEDChannels[1][0] = 200;
   LEDChannels[2][0] = 500;
   LEDChannels[3][0] = 700;
   LEDChannels[8][0] = 900;
   LEDChannels[9][0] = 700;
 
  WriteLEDArray();
   delay(200);
//4   
   LEDChannels[2][0] = 200;
   LEDChannels[3][0] = 500;
   LEDChannels[4][0] = 700;
   LEDChannels[5][0] = 900;
   LEDChannels[6][0] = 900;
   LEDChannels[7][0] = 800;
   LEDChannels[8][0] = 700;
   LEDChannels[9][0] = 500;

   WriteLEDArray();
   delay(200);
//5   
   LEDChannels[1][0] = 0;
   LEDChannels[2][0] = 0;
   LEDChannels[3][0] = 200;
   LEDChannels[4][0] = 500;
   LEDChannels[5][0] = 700;
   LEDChannels[6][0] = 700;
   LEDChannels[7][0] = 700;
   LEDChannels[8][0] = 500;
   LEDChannels[9][0] = 300;

   WriteLEDArray();
   delay(200);
//6   
   LEDChannels[3][0] = 0;
   LEDChannels[4][0] = 200;
   LEDChannels[5][0] = 500;
   LEDChannels[6][0] = 500;
   LEDChannels[7][0] = 300;
   LEDChannels[8][0] = 200;
   LEDChannels[9][0] = 100;

   WriteLEDArray();
   delay(200);
//7   
   LEDChannels[4][0] = 0;
   LEDChannels[5][0] = 200;
   LEDChannels[6][0] = 300;
   LEDChannels[7][0] = 200;
   LEDChannels[8][0] = 100;
   LEDChannels[9][0] = 0;
   LEDChannels[9][1] = 250;
   LEDChannels[9][2] = 350;
 
   WriteLEDArray();
   delay(200);
//8   
   LEDChannels[5][0] = 0;
   LEDChannels[6][0] = 350;
   LEDChannels[7][0] = 250;
   LEDChannels[8][0] = 0;
   LEDChannels[8][1] = 250;
   LEDChannels[8][2] = 350;
   LEDChannels[9][1] = 0;
   LEDChannels[9][2] = 800;
 
   WriteLEDArray();
   delay(200);
//9   
   LEDChannels[6][0] = 0;
   LEDChannels[7][0] = 0;
   LEDChannels[8][1] = 300;
   LEDChannels[8][2] = 420;
   LEDChannels[9][2] = 1023;
 
   WriteLEDArray();
   delay(200);
//10
   LEDChannels[8][1] = 0;
   LEDChannels[8][2] = 1023;
   LEDChannels[9][2] = 1023;
 
   WriteLEDArray();
   delay(800);
}
Logged

Pages: [1] 2 3   Go Up
Jump to: