Indeed. The example was to visualize what was going on.
Now the mission for @davy-ps, should he choose to accept it, is to learn how to program.
By the way I used a computer program to generate most of the data you see in the example above I didn't spend time actually typing it all in. So I could make it as long as I wanted the only limit being storage space. But if you have the algorithm to generate the data then you don't need to store it.
Being able to use tables and lists of data in your program is still important.
Once again Guys, thanks for your help. Taking on board what you said, I have gone to the rudiments of programming to instil a logical sequence in my head of how to put a programme together to achieve the desired effect. I downloaded the Arduino Programming Book too. The sketches you have sent are fantastic but generally I don't have a clue how they work or how to edit them.
I have put together the attached sketch designed from my own knowledge and the takeaway is (Thanks to Paul McWhorter) I now fully understand the for loop (in this context anyway.) I have made comments on sketch and if you have time I would appreciate any improvements you can see. I am going to play around with sketch and try and add some different colours. Probably through fastLed.
Cheers,
Davy.
int redLED = 4; //Assigns Arduino PIN 4 for red LED int blueLED = 5; //Assigns Arduino PIN 5 for blue LED int greenLED = 6; //Assigns Arduino PIN 6 for green LED int onTime = 1000; // delay int offTime = 1000; // delay int numRedBlink = 8; int numBlueBlink = 0; int numGreenBlink = 0; int redOnTime = 1000; //This is the redLED on time int redOffTime = 1000; //This is the redLED off time (delay) int blueOnTime = 1000; //This is the blueLED on time int blueOffTime = 1000; //This is the blueLED off time (delay) int greenOnTime = 1000; //This is the greenLED on time int greenOffTime = 1000; //This is the green LED on time (delay) void setup() { // put your setup code here, to run once: pinMode (redLED, OUTPUT); pinMode (blueLED, OUTPUT); pinMode (greenLED, OUTPUT); } void loop() { // put your main code here, to run repeatedly: for (int j = 1; j <= numRedBlink; j = j + 1) { // for loop. Will loop through code for specified CYCLES. // Curly brackets inserted to denote loop within loop. // j = counter. This can be declared as a global variable IE before // void setup, or as a local variable within the for loop. // j is equal to 1. // j<=numRedBlink; Gets this information from int at top of page. Can also be expressed as a whole number. // in this case 8 cycles. // j=j + 1. When the cycle limit of 8 is reached loop will restart // if another loop is present it will start. digitalWrite(redLED, HIGH); //Turn red LED on. digitalWrite(blueLED, HIGH); digitalWrite(greenLED, HIGH); delay (redOnTime); digitalWrite(redLED, LOW); //Turn red LED off. digitalWrite(blueLED, LOW); digitalWrite(greenLED, LOW); delay (redOnTime); } digitalWrite(redLED, HIGH); delay (redOnTime); digitalWrite(redLED, LOW); delay (redOnTime); digitalWrite(blueLED, HIGH); delay (blueOnTime); digitalWrite(blueLED, LOW); delay (blueOnTime); digitalWrite(greenLED, HIGH); delay (greenOnTime); digitalWrite(greenLED, LOW); delay (greenOnTime); }
I just viewed Paul's Arduino Tutorial 15: Understanding Arduino For Loops to see how he made it so clear.
At 38.30
I believe this is a pervious incarnation.
LESSON 3 - Arduino For Loops and LED Circuit
The sketches you have sent are fantastic but generally I don't have a clue how they work or how to edit them.
Ouch! And they were so clear to me
😉 As is everything if you know how.
I followed this to insert code
It doesn't seem to retain the indents making it hard to see the blocks of code. Saving as HTML will also retain colour coding which for me makes reading the code easier.
Ouch! And they were so clear to me
As is everything if you know how.
Sure but apparently Paul McWhorter has nailed it. The tutorial essentially did what I did showing the loop rolled out in one sketch and then showing it enclosed in a for loop in another sketch for turning a row of leds on/off.
Sure but apparently Paul McWhorter has nailed it. The tutorial essentially did what I did showing the loop rolled out in one sketch and then showing it enclosed in a for loop in another sketch for turning a row of leds on/off.
We all learn differently. I couldn't (and still can't 😉 ) do long division the way I was shown at school but could do them in my head. I was never given any marks as there was no working out provided. One day the teacher hauled me out on the floor and got five random numbers from the class plus a double digit divisor and told me to work it in my head while she done it her way. The purpose being to make an arse of me in front of the class. We both arrived at the same answer in about the same time and she told me to back to my desk and reminded me that nobody likes a Smart Alec.
Nine years old.
I couldn't (and still can't 😉 ) do long division the way I was shown at school but could do them in my head.
Doing something in your head without explaining the steps involved means you cannot share whatever those steps are or program a computer to do division.
Is this better?
Yes, it is better, thanks.
Anything seems possible when you don't know what you're talking about.
Hi Mate. I have been playing around with your Opposite Direction Theatre Chase code. Finally sussed out how to change the colours ;-). Couple of things have me stumped. I have tried a few different permutations but to no avail. I have asked a couple of questions in the attached sketch in the form of commented question marks. If you get a bit of time can you have a wee look at it?
I'm not @robotBuilder, but I'll have a go at answering your questions ...
#define LED_PIN 4 #define NUM_LEDS 10 //???? What does this value affect? If I change 6 to 0 for example, code still runs. #define NUM_COLOURS 6 #define NUM_REPEATS 1
The #defines set a value to the symbolic names. It's good practise to avoid using "magic" (i.e. explicit numbers other than 0,1,-1 for example) numbers when programming, This allows for easy changes later.
Your program may need to refer to the LED pin in many different places. If you used the literal value 4 in all of them and then needed to move the LED to another pin, you'd have to find all the 4s (and only the 4s that represented the LED pin) and change them.
By representing the pin number by a self-describing name in a #define statements and using the name LED_PIN every time you refer to that pin then you could change the pin you use by just changing the value in ONE place.
It also helps when you have multiple pins with a similar use. For instance if you used 3 (4,5 and 6, say) pins to light 3 different LEDs, then your program would be much easier to read if you #defined them as, for instance
#define leftLED 4
#define rightLED 5
#define offLED 6.
If you needed to signal left and off you could write
digitalWrite(4,HIGH);
digitalWrite(6,HIGH)
And you'd have to go back to your wiring diagram to see what it meant.
However, if you wrote it as
digitalWrite(leftLED,HIGH);
digitalWrite(offLED,HIGH)
The meaning would be instantly apparent.
-----------------
In your sample sketch the value of NUM_COLOURS is meaningless as you don't use it. In the previous sketch from which you "adapted" this, NUM_COLOURS was used as the dimension of the colourList array. Again, having this value #defined allows you to change the colourList without having to search the whole sketch finding and changing every occurrence of the array limit. This value will often appear in for loops and other such constructions.
Since you never use the value, it doesn't matter what number you assign to it.
-----------------
If you want to add a second loop with different colours, then create a second array and populate it with colours (as you've done.
Not sure what you mean by adding a second loop. You're only showing one loop. What you're doing now is populating the leds array with colours from colourList and then immediately OVERWRITING them with colours from colourList2.
The LEDs can't display two colours at once.
Try inserting FastLED.show(); delay(500); between the for loops.
Anything seems possible when you don't know what you're talking about.