Pages: 1 [2] 3   Go Down
Author Topic: Similar to KITT light bar but not...I need help please  (Read 3627 times)
0 Members and 1 Guest are viewing this topic.
SF Bay Area
Offline Offline
Edison Member
*
Karma: 11
Posts: 1244
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The SPI stuff is not what's causing you problems, since that's all completely abstracted out. If you just use the WriteLEDArray() functions as delivered, you simply have a 1xN "screen" of RGB pixels in LEDChannels[N][3]. So the part that's causing you problems is figuring out your graphics algorithms...you would be having the same problems if you tried to write the program in Visual Basic or Processing. You just need to step back and think of how you can tell each pixel to be the correct color at various points in time.
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

Ok, a sat back and stared at it the code a while wondering how to go about this and have come up with an idea. Please tell me if there is an easier way to try to go about this and/or what yall think about this idea.

I'm thinking I need to implement a for loop that will read the values of each led and use that value as the max and fade it to zero from there (for my red LEDs only) and use a separate for loop for the last 2 leds in the string which fades them from red to cyan to blue.
?

Logged

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

This is what I was thinking....

//1
   for (int i=0; i<10; i++)                 <-- Line 65 it is referring to.
   {
     LEDChannels
  • = 1023;
     LEDChannels[1] = 0;
     LEDChannels[2] = 0;
   }
   WriteLEDArray();
   delay(2000);
//2   
for (int i=1023; i=1023; (i-200));
  {
   LEDChannels[0][0] = i;        <-- Line 76 it is referring to.
   LEDChannels[1][0] = i;
   LEDChannels[2][0] = i;
   LEDChannels[8][0] = i;
   LEDChannels[9][0] = i;
  }
   WriteLEDArray();

I keep getting:
 
basicShiftbrite.cpp: In function 'void loop()':
basicShiftbrite:76: error: name lookup of 'i' changed for new ISO 'for' scoping (this is in //2)
basicShiftbrite:65: error: using obsolete binding at 'i'
Logged

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

I have been trying to lead you in the right direction, but not providing too many details, because I didn't want to cheat you out of the thrill of success when it all clicked and you figured it out. (Maybe you don't believe in this, but if someone helps me too early it's like spoiling the end of a movie, or pointing out the piece of the puzzle I was trying to find.)

The final, root cause of the problem here is that you don't know how to write code in C. OK...few people really ever truly do know how, but most programmers and many electrical engineers have a working ability in it. This is the course of action I recommend:

1. For this project, just ask for a solution. I could write the code for you pretty quickly.
2. For future projects, go get a book about C programming and work through it. Find one that suits your learning style and speed. Many would recommend Kernighan & Ritchie, you might find something else that works well. The Sams books aren't all bad...just don't expect to actually learn C in 24 hours.

Absolutely, 100% do not be embarrassed by this. I can see that you have been trying hard to get this to work, you ARE learning (just not in a structured enough manner) and you are far beyond many of the people who come into these forums asking only for cut & paste solutions, and who refuse to learn anything at all. I know for a fact you will pick up C quickly, and probably come back in here to teach us a few things. smiley

Let me know if you want a code example that shows the LED effect you're hoping to see.
Logged

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34230
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Think "blink without delay" sort of structure enlarged to cope with say three LEDs, but instead of just turning an LED on or off when the millis() count gets exceeded just alter the value in one LED colour and write out your array again.

In this way you get different fades going on at the same time.
Logged

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

I feel the same way about the spoiling the ending, I don't want this just given to me because I want to learn how to do it myself.
I'm glad to see your responses though cause I was wondering how badly I was getting on nerves by asking question after question about something that should not be so difficult. Very nice to have people willing to "show me the way".  smiley-grin

I am going to pick up a book (or ten) on C tonight when I get off work.
If only my schooling would hurry up so I can take my elective programming courses. I know what the first language I take will be....
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34230
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
asking question after question about something that should not be so difficult
Hey that's what this forum is all about.  smiley

When writing a program you have to do two things at once.
1) Have an algorithm for what you want to do.
2) Implement that algorithm in the language you are writing in.

It helps when you first start to split those two thing up. I advise that you first of all draw a flow diagram of what you want to do and when. Go through it box by box and when you think you have it right then go on to step 2 and write the C statements to implement it. It is the way I still work for implementing the more complex stuff.
Logged

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

And for creating the algorithm....Let's say you have a number, called x. Make it count from 0 to 100, step by step. At each step, what does each LED in your array need to look like? Try to express that as a set of formulas. Maybe even make it work on any length LED array. You can also work in scales that have nothing to do with your actual LED array; only converting the brightness at each discrete LED location as the last step in the process.
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

Good morning fellas.

So I am trying to use the millis() timer to setup a "counter" so that I can control the brightness of the LEDs in a smoother fashion than delay() allowed. Using your idea macegr just not sure if I am doing it the way you had in mind.
Per Grumpy_Mike's suggestion I have an "algorithm" in mind that I would like to implement and it is as follow (except the LEDChannels 1023 and 0 examples would be my specific brightness values values).

I'm just trying to get a grasp on this millis() before I try implemeting it into my code but I can't even get this to flash right.

Code:
int w0 = 0;
int w1 = 200;
long restart = 2400;
...
... //setup code and what not.
...
void loop() {
//1

if (millis() >= w0)                      // If millis() is >= 0 (w0), then start the sequence by setting all LEDs full brightness
{
for (int i=0; i<10; i++)
   {
     LEDChannels[i][0] = 1023;
     LEDChannels[i][1] = 0;
     LEDChannels[i][2] = 0;
   }
   WriteLEDArray();
   Serial.println("ON");
   w0 = millis() + restart;          // After setting full brightness don't do this again for 2400 milliseconds or 2.4 seconds
}
if (millis() >= w1){                    //Now 200 milliseconds after setting full brightness lets shut it off
  for (int i=0; i<10; i++){
    LEDChannels[i][0] = 0;
    LEDChannels[i][1] = 0;
    LEDChannels[i][2] = 0;
  }
  WriteLEDArray();
  Serial.println("OFF");
  w1 = millis() + restart;          //Don't do this again for 2400 milliseconds or 2.4 seconds
}}

doing this my timing does not stay how I would like it.
This is how its working in my head...but not working in practice.

If I turn on at 0 then turn off 200ms later but I'm waiting 2400ms to turn on again then I should turn back on in 2200ms after turning off.


..?..Maybe its time for me to see an example of what I'm trying to do..?..
« Last Edit: August 29, 2011, 01:13:36 pm by ibourdon » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34230
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

w0 and w1 both need to be long ints.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34230
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The other thing is that code will only work if millis() returns zero at the very beginning. You have no way of knowing if that is true.
If millis() was at a value greater than 200 when you first encounter loop() then those two if() statements will go off at the same time.
So to get round that in your setup() function have:-
w0 = millis();
w1 = millis() + 200;

Or perhaps:-
w0 = millis() + restart;
w1 = millis() + 200 + restart;
Logged

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

Awesome! I got it working properly thanks to your suggestion to put this in the setup.
 
Quote
w0 = millis();
w1 = millis() + 200;

But unfortunately changing everything to millis() and getting rid of the delay() did nothing for the fade effect save for the tiniest amount of smoother fading.

So I have my arrary of LEDChannels :

int LEDChannels[NumLEDs][3] = {0};

How can I use that with another variable to change the pwm setting on each LED down the line to get the proper fade effect?
Sorry guys, this fading effect is kicking my A**

Thanks
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34230
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
changing everything to millis() and getting rid of the delay() did nothing for the fade effect
Well no that code was never going to fade, did you expect it to?

The algorithm for fading is to decrease the LED brightness by small amount very frequently. All your code did was flash on and off.
Have a counter with 1023 in it, each time you time out you decrement this counter and then write the counter value out to your array:-
Code:
LEDChannels[i][0] = counter;
When the counter reaches zero you have got to the end of your fade.
« Last Edit: August 31, 2011, 11:21:02 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

I was hoping that the code I had would give it the illusion of fading but it did not.

I took a little break today from this project and tackled another small project which I needed the LEDs (12 strips of 9 LEDs, and 4 strips of 12 LEDs attached to 2 ULN2803A's) to chase each other (trailing edge) and did it with all my OWN code, no copy & pasting or anything like that anywhere. So proud!...

I used some bit banging to get the desired effect I was looking for. Learned something new which I hope will help with this project when I get back to it in the morning.

What you are saying is what I was thinking I need to do, I just don't know how to get all my timing to go off of that 1 timer.
I will ponder about that tonight and see if I can come up with a solution.
I just don't know how to implement the counter so that is changes the brightness for all of them in sequence (not at the same time).

But the project I just finished did give me a few ideas on how to get this working properly.

« Last Edit: August 30, 2011, 05:06:02 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

Ok, I have gotten it to partially fade.
Out of the 10 LEDs I'm working with I have managed to get the top 8 to fade from red to nothing but have not been able to get the last 2 to fade from red to blue simultaneously. And so far my fade is fading all the leds at the same time not in sequence.

I can not seem to get the red to fade to off (leds 0-7) & the red to fade to blue (leds 8, 9) at the same time.

--EDIT--

Crap, I just realized I was trying to write to my blue channel using LEDChannels(i)(3) instead of (2)...
No wonder I could not get any blue to fade..
Got the LEDs I need fading the colors, just need to get it to sequence now...

ALMOST THERE, YAY!
« Last Edit: August 31, 2011, 12:45:25 pm by ibourdon » Logged

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