Go Down

Topic: ~(solved)Wave Pattern~ (Only Single Sided Snake Trail!!!!!) (Read 4255 times) previous topic - next topic

Nishant_Sood

Oct 01, 2013, 09:25 pm Last Edit: Oct 05, 2013, 09:19 pm by NI$HANT Reason: 1
I have this>> http://www.youtube.com/watch?v=oVGDMrQmWKc  wave working in the single side but I want the same wave to flow the other way too! which until now I'm not able to accomplish actually it should be a matter of just decrementing the values of RED led brightness systematically  and incrementing the brightness systematically in this line >>  Addup = Addup - 655360;  to achieve the desired effect but it isn't working right now, May be I'm wrong which is not a big deal it happens in programming.
The Strip that I'm working is a WS2801 chip and it's available here >> https://www.sparkfun.com/products/11272

Here's the code>> http://pastebin.com/5Xu4VWKC
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

PaulS

I don't do rubbish bin. Post the code as an attachment.
The art of getting good answers lies in asking good questions.

hib1

I would try this if  "STRIP_LENGTH" is the number of LEDs in your strip.

Code: [Select]


//Runs a wave of LED's backwards
void post_frame_moreLEDS_back (long LEDcolor, int startLED, int endLED) {

  for(int LED_number = STRIP_LENGTH ; LED_number =0; LED_number--)




Nishant_Sood

@PaulS

Please have the code as an Attachment (I originally wanted to post code within the post but it said its too much!)
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

Nishant_Sood

"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

PaulS

Code: [Select]
unsigned long prevValue , currValue, Addup = 16711680, this_led_color;
Magic numbers need explanations.

Code: [Select]
  for(int x = 0 ; x < STRIP_LENGTH ; x++)
    strip_colors[x] = 0;

Global variables are initialized for you.

Code: [Select]
  if (endTime - startTime < 30 && checkBUTTON == false){
    rightWIDTH = 29;
    Serial.println("30 leds");
  }
  else if (endTime - startTime >= 30 && endTime - startTime <= 40 ) {
    rightWIDTH = 34;
    Serial.println("35 leds");
  }
  else if (endTime - startTime >= 40 && endTime - startTime <= 50 ) {
    rightWIDTH = 39;
    Serial.println("40 leds");
  }
  else if (endTime - startTime >= 50 && endTime - startTime <= 60 ) {
    rightWIDTH = 44;
    Serial.println("50 leds");
  }
  else if (endTime - startTime >= 60 && endTime - startTime <= 70 ) {
    rightWIDTH = 49;
    Serial.println("60 leds");
  }
  else if (endTime - startTime >= 70 && endTime - startTime <= 80 ) {
    rightWIDTH = 54;
    Serial.println("70 leds");
  }
  else if (endTime - startTime >= 80 && endTime - startTime <= 90 ) {
    rightWIDTH = 59;
    Serial.println("80 leds");
  }
  else if (endTime - startTime >= 90 && endTime - startTime <= 100 ) {
    rightWIDTH = 64;
  }
  else if (endTime - startTime >= 100 && endTime - startTime <= 110 ) {
    rightWIDTH = 69;
  }
  else if (endTime - startTime >= 110 && endTime - startTime <= 120 ) {
    rightWIDTH = 74;
    Serial.println("75 leds");
  }
  else if (endTime - startTime >= 120 && endTime - startTime <= 130 ) {
    rightWIDTH = 80;
    Serial.println("75 leds");
  }
  else if (endTime - startTime >= 130 && endTime - startTime <= 140 ) {
    rightWIDTH = 84;
    Serial.println("75 leds");
  }
  else if (endTime - startTime >= 140 && endTime - startTime <= 150 ) {
    rightWIDTH = 89;
    Serial.println("75 leds");
  }
  else if (endTime - startTime >= 150 && endTime - startTime <= 160 ) {
    rightWIDTH = 94;
    Serial.println("75 leds");
  }
  else if (endTime - startTime >= 160 && endTime - startTime <= 170 ) {
    rightWIDTH = 99;
    Serial.println("75 leds");
  }
  else if (endTime - startTime >= 170 && endTime - startTime <= 180 ) {
    rightWIDTH = 104;
    Serial.println("75 leds");
  }
  else if (endTime - startTime >= 180 && endTime - startTime <= 190 ) {
    rightWIDTH = 109;
    Serial.println("75 leds");
  }
  else if(endTime - startTime > 190){

There would be a hell of a lot less typing, and calculating, if you calculated endTime - startTime ONCE.

Code: [Select]
    post_frame_moreLEDS_testing(0x000000, a, a+size2);
How does that differ from 0 or 0x0 or 0b0?

Code: [Select]
void post_frame_moreLEDS_testing (long LEDcolor, int startLED, int endLED) {


Out the curly brace on the line with the statement, to save a line. Then, add a blank line. Makes sense to me. NOT!

Code: [Select]
      this_led_color = 0x000000; //24 bits of color data
No, it isn't.. 0x000000 is still 0. That's a 16 bit 0.

Code: [Select]
          Addup = Addup - 655360;   
    for(byte color_bit = 23 ; color_bit != 255 ; color_bit--) {
        Addup = Addup + 655360;     
        for(byte color_bit = 23 ; color_bit != 255 ; color_bit--) {

More magic number with no explanation.

Having read through your code, I still can't understand what your problem is.
Quote
but it isn't working right now

That's pretty lame, you know. The code does something. Only you can see what it does.
The art of getting good answers lies in asking good questions.

Nishant_Sood

#6
Oct 04, 2013, 07:39 am Last Edit: Oct 04, 2013, 07:50 am by NI$HANT Reason: 1
Quote
unsigned long prevValue , currValue, Addup = 16711680, this_led_color;


You just need to be considered with variables Addup(this 16711680 depicts 0xFF0000 in decimal form) and this_led_color is the variable that stores color that is to be loaded to the latest LED in the for loop.

Sorry for ignorance these must have been defined by me.

Quote
There would be a hell of a lot less typing, and calculating, if you calculated endTime - startTime ONCE.


I just typed one IF condition and then copied and pasted the other statements so that doesn't make any difference, although you are right.

Quote
Only you can see what it does.


Well you can see it too ,on the very first post I posted a YouTube video which shows the animation the function >>post_frame_moreLEDS_testing() is making YOU JUST NEED TO CONSIDER THIS FUNCTION AS THIS IS THE PLACE WHERE IT NEEDS CHANGES TO RUN THE ANIMATION THE OTHER SIDE.

Basically if you will see the video then you'll see that the snake trail animation is running from left to right only! I'm trying to also have it run from right to left!
http://www.youtube.com/watch?v=oVGDMrQmWKc

In the video you can see the flow is going from left to right!

How it's happening is by adding to or deducting to the variable Addup, If the variable Addup is initially declared with 16711680 value(that is 0xFF0000 red full on) then deducting it by 65536 deducts 1 bit in the 0 to 255 byte range so basically i'm controlling the brightness(decreasing it) like this as such when the statement (Addup = Addup - 655360;    )runs embedded under the for loop it deducts 10 x 65536 values for fast effect on the wave.

But the problem is that the wave flow effect I think must run from other side if I make the Addup variable = 0 and then add values in the forloop(in the statement Addup = Addup + 655360;) thus increasing the brightness but it shows the same effect?!!
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

PaulS

Quote
this 16711680 depicts 0xFF0000 in decimal form

Oh, well, that's obvious. Why not simply use 0xFF0000 in the code?

Quote
I just typed one IF condition and then copied and pasted the other statements so that doesn't make any difference, although you are right.

Your statement may be true regarding the amount of typing. It is not true that it makes no difference. Calculating the difference 20 times takes longer than calculating it once. Though the compiler may be smarter than you, and generate the proper machine code to do the calculation only once.

The art of getting good answers lies in asking good questions.

Nishant_Sood

Quote
Why not simply use 0xFF0000 in the code?


just for the clarity of the thought process.

yes you are true that the Compiler mabe smart its my duty to do the time Calculation once.

Any insights on the Animation working?
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

int2str

I just typed one IF condition and then copied and pasted the other statements


*sigh*

I think somebody should develop a keyboard for programmers, that automatically lights your fingers on fire if you copy the same section of code more than once.

1. Use functions
2. Use arrays, loops and most importantly: math instead of cascades of "if" statements

If you make your code clear, concise and driven by a loop, reversing the order will be no problem.

Nishant_Sood

Quote
think somebody should develop a keyboard for programmers, that automatically lights your fingers on fire if you copy the same section of code more than once


Okay that's fine

But you won't havr said this if it was for a switch case statement you see this is what they are made for although what you say is correct and implicable but aattimes when you have to implement fast functions that work flawlessly you don't have the time to think about the for loops off course these cascades of if conditions can be later on converted into switch or for loop things but the time called for focusing on some other part of the system also these if conditions play no role in creation of the needed Animation
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

PeterH


But you won't havr said this if it was for a switch case statement you see this is what they are made for although what you say is correct and implicable but aattimes when you have to implement fast functions that work flawlessly you don't have the time to think about the for loops off course these cascades of if conditions can be later on converted into switch or for loop things but the time called for focusing on some other part of the system also these if conditions play no role in creation of the needed Animation


I'm sorry to contradict you, but that is completely wrong in every respect. The way to develop flawless code fast is to use the most appropriate control constructs in the first place, don't introduce duplicate code in the first place and don't use error-prone bug-encouraging approaches like copy/paste. If you "don't have time" to do it right because you are "focusing on some other part of the system" then you certainly don't have time to waste on a slower, more error-prone approach. Doing it right produces shorter, simpler code which takes less time to write and test and fix.

Nishant_Sood

I have solved the problem! With the same set of code
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

int2str


I have solved the problem! With the same set of code


This is not success.

Now that you've hacked the Sparkfun example code to high hell to get it to do what you want, I would take that opportunity to rewrite the code and implement a new algorithm that does the same thing in an understandable and readable way.
If you're at all interested in improving your coding, this would be a great project to tackle.

Btw. while I'm fairly sure the Sparkfun example code is public domain, I think you should still give them some credit if you're essentially using it as-is and then just adding your bits. Also, the Sparkfun example code isn't all that great to be honest, so if you decide to re-write it, I'd start from scratch if I was you.

Nishant_Sood

#14
Oct 05, 2013, 09:37 pm Last Edit: Oct 05, 2013, 09:52 pm by NI$HANT Reason: 1
Quote
This is not success.


Yes it is, You don't even care about what my real problem was the things you are talking are correct but come along with what I want and not push the ultimate question back as you did.
I will make the code formulated

Quote
Btw. while I'm fairly sure the Sparkfun example code is public domain, I think you should still give them some credit if you're essentially using it as-is and then just adding your bits.


Quote
Now that you've hacked the Sparkfun example code to high hell to get it to do what you want


Now are you fumed I think you are because Whatever I was able to make it work, What's your problem just keep it at your part.
Talk responsibly don't  use aggressive words like hell or whatever you think its fine for you.

Quote
I think you should still give them some credit if you're essentially using it as-is and then just adding your bits. Also, the Sparkfun example code isn't all that great to be honest,


Have you seen the code that is with me and it's working? that you are assuming that I'm giving them credit or not? I'll tell, You haven't seen it you are just talking in the air.
Everybodies using libraries we use tonne's of them already while using c/c++/c#/java and I'm not even using any here in my program.
People like you are there to put other's down that's it but remember you don't get up and achieve anything by putting down other's may be its personal gratification for you.
(I'm sorry for you ,your words are all spitting fire and they no longer seem to be there clear things but are there to insert disgust feeling.)

Quote
If you "don't have time" to do it right because you are "focusing on some other part of the system" then you certainly don't have time to waste on a slower, more error-prone approach.


@PeterH thank you I will take care or that.

"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

Go Up