Hello all,
I’m hoping someone can help me with to tidy up some very basic C+ code for an Arduino Mega based project.
I have 2 rows of LEDs – 15 LEDs in both row, using Pins 22-51 as Outputs. I have written some very basic code to create 3 separate patterns / loops(). Each separate code works fine (on an emulator).
The patterns are just different versions of turning on and off LEDS as needed.
An example is
<void loop() {
// single LED chase
digitalWrite(22, HIGH);
delay(200); // Wait for 200 millisecond(s)
digitalWrite(22, LOW);
digitalWrite(24, HIGH);
delay(200); // Wait for 200 millisecond(s)
digitalWrite(24, LOW);
digitalWrite(26, HIGH);
delay(200); // Wait for 200 millisecond(s)
digitalWrite(26, LOW);
digitalWrite(27, HIGH);
delay(200); // Wait for 200 millisecond(s)
.
.
.
digitalWrite(27, LOW);
digitalWrite(25, HIGH);
delay(200); // Wait for 200 millisecond(s)
digitalWrite(25, LOW);
digitalWrite(23, HIGH);
delay(200); // Wait for 200 millisecond(s)
digitalWrite(23, LOW);
delay(200); // Wait for 200 millisecond(s)
}
etc…
If I put all the patterns in one loop, the code will be very long, especially if I want to run Pattern #1 three times, run Pattern #2 once, run Pattern #3 four times, or whatever.
I remember from years ago that actual loop() code to run the patterns; can be put at the bottom of the code and ‘pulled’ in when needed but I can’t remember how to do it (or the correct terminology)
I think the layout should look
void setup()
{
pinModes:
}
void loop()
{
Run Pattern #1
Run 3 times
Run Pattern #2
Run 8 times
Run Pattern #3
Run 10 times
Run Pattern #2
Run 2 times
}
{
Code for Pattern #1
}
{
Code for Pattern #2
}
{
Code for Pattern #3
}
I'm sure the brackets are in the wrong places here.
Thanks in advance.