Notifications
Clear all

Theatre chase in opposite directions.

155 Posts
6 Users
2 Likes
10.7 K Views
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

@robotbuilder 

@will 

I feel that I should apologize to the forum though because I don't really think that this is a proper environment for learning to code, just solving individual problems when they come up.

In my opinion, there are many YouTube videos and other sites that are better suited for the task of education.

I fell into the "teacher mode" without fully realising how hard it was. The same issue exists for electronic projects when someone doesn't understand basic electronic concepts.

Still tinkering is fun way to start and get motivated to explore deeper as @davy-ps did when directed to mcwhorter's tutorials to learn about for loops. With Arduino electronic projects others might be motivated to better understand the basic electronic concepts involved.

Usually I don't have the hardware involved in a question and thus can't really provide a useful reply.

 

robotBuilder and @will.

                                   Guys, I have learned so much from you in a short space of time. True, most of the information I have is stored like a 1000 piece jigsaw in my head and I am just starting to complete one border. ;-). A perfect example is the YouTube page robotBuilder asked me to look at "Fast Led Basics " I watched that a little while back and it was double Dutch to me. Now I have some (not comprehensive yet) idea what the guy is talking about. I was too bull at a gate trying to get a finished code for my original idea, but as in all walks off life if something is broken and you don't know how it's supposed to be, then you cant fix it.

I am now wholeheartedly trying to get the rudiments of programming in my head, thanks to your encouragement.

 

Cheers,

 

Davy

 

PS Codecage. This is meant to be a humorous comment, so please take it that way!

Judge says to a guy in court,

"You have been found guilty! Sentence is 30 days in jail, or a $1000!"

Guy says,

"I'll take the money."

 

😉


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

@davy-ps 

CRGB leds[NUM_LEDS];//?????????????????????????????????

This creates a list of NUM_LEDS (10 in this case) of CRGB objects (which hold the red,green,blue values in each object) which is used by the FastLEDS.show method as input.

You can't put something in a list that doesn't exist.

So first you create the list,

CRGB leds[NUM_LEDS];

You then let FastLEDS know to use that list.
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

And now you can use it to enter a CRGB object in that list say as item 4 in the list.

leds[4] = CRGB(255,10,8); 

You could have given the list another name say dogs.
CRGB dogs[NUM_LEDS];
And let FastLED know to use that list.
FastLED.addLeds<WS2812,DATA_PIN,RGB>(dogs,NUM_LEDS);

And then use that list (which is a list of CRGB objects),

dogs[4] = CRGB(0, 255, 255);

FastLED.show(); // copy leds[] values to actual leds

//Need explanation on this function. Under impression it turned LED off.

No. It uses the leds[] array to determine what colors to "show" in the row of leds connected to the Arduino. 

 


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

@robotbuilder 

 

Thanks Mate. Will have a wee play around with it.

 

PS 

When you cut and paste comments for reply, how do you get them in a box?


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

@davy-ps 

Drag the mouse over the text with select button down to highlight it then hit the "" in the top menu bar.

 


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

@robotbuilder 

Drag the mouse over the text with select button down to highlight it then hit the "" in the top menu bar.

Thanks Mate.

 


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

@robotbuilder 

The for loop will change the value of ledNumber with each cycle but you change the colors within one cycle one after the other without the ledNumber changing its value.

Ha! I was messing about with curly braces and not applying for command to each colour.


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 
Posted by: @davy-ps

@robotbuilder 

Getting the hang of this now. But some things I cannot see. This is a modified version of your Two Direction / Two Colour code. It now has 2 patterns and four colours.

So, I added another for loop (last one on code) to individually control LEDs. After a bit of mucking around I got it to display the desired effect...................However.....As you can see in video LED 8 stays HIGH. In an earlier version when I was only switching on LED 0, LEDs 1 and 8 would be HIGH.

That's because the last matrix line (at j=18) doesn't shut off the LED when it leaves the for loop. So, the second last LED stays lit as you left it. 

Note that it also leaves the second LED lit as well, but you don't see that because you start flashing LEDs 0 and 1 in the next for loop.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

@will 

Hi Will,

That's because the last matrix line (at j=18) doesn't shut off the LED when it leaves the for loop. So, the second last LED stays lit as you left it. 

So how do I shut it? I thought once the loop was complete the next one would start without any over-run from the previous.

Note that it also leaves the second LED lit as well, but you don't see that because you start flashing LEDs 0 and 1 in the next for loop.

Yes I did notice that as I said in my post.

.....However.....As you can see in video LED 8 stays HIGH. In an earlier version when I was only switching on LED 0, LEDs 1 and 8 would be HIGH.

😉

Thanks Mate. 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 
Posted by: @davy-ps

@will 

Hi Will,

That's because the last matrix line (at j=18) doesn't shut off the LED when it leaves the for loop. So, the second last LED stays lit as you left it. 

So how do I shut it? I thought once the loop was complete the next one would start without any over-run from the previous.

When the loop ends, the LEDs are left in the last state you set them. Think about it, it would be impossible to get anything done if the system reverted to whatever it was before you issued your commands.

If you want to shut the LEDs off after you exit the last colour loop, then you need to explicitly turn them off. You can do that by setting the ones you know are still on to black, or you can use a for loop (i=0 to NUM_LEDS) to set all of them black.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

@will 

 

Cheers Mate. That worked and makes sense too. 

leds[8] = CRGB(0,0, 0); //Red LED
FastLED.show();

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@davy-ps 

Always remember that the computer always does exactly what you told it to do, whether that's what you meant for it to do or not.

It has absolutely NO capacity for judging whether something is reasonable or desirable.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Page 9 / 11