Go Down

Topic: Similar to KITT light bar but not...I need help please (Read 7932 times) previous topic - next topic


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.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store


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.


This is what I was thinking....

   for (int i=0; i<10; i++)                 <-- Line 65 it is referring to.
  • = 1023;
         LEDChannels[1] = 0;
         LEDChannels[2] = 0;
    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;

    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'


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. :)

Let me know if you want a code example that shows the LED effect you're hoping to see.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store


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.


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".  :D

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....


asking question after question about something that should not be so difficult

Hey that's what this forum is all about.  :)

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.


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.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store


Aug 29, 2011, 06:06 pm Last Edit: Aug 29, 2011, 08:13 pm by ibourdon Reason: 1
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: [Select]

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

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;
  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;
 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..?..



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;


Awesome! I got it working properly thanks to your suggestion to put this in the setup.
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**



Aug 30, 2011, 10:21 pm Last Edit: Aug 31, 2011, 06:21 pm by Grumpy_Mike Reason: 1
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: [Select]
LEDChannels[i][0] = counter;
When the counter reaches zero you have got to the end of your fade.


Aug 31, 2011, 12:02 am Last Edit: Aug 31, 2011, 12:06 am by ibourdon Reason: 1
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.


Aug 31, 2011, 07:30 pm Last Edit: Aug 31, 2011, 07:45 pm by ibourdon Reason: 1
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.


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...


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131