Two parts within this project:
-
I've got 14 blue LEDs that I want to repeatedly "fill up" like a bar graph.
-
I have 4 red LEDs that I want to essentially turn on and off consecutively, as seen in the video.
The pot to adjust the speed is unnecessary for me, at this time.
So I've been able to, in two separate sketches, achieve each of these things individual by simply using the most basic programming, setting each LED to high and low, but of course that doesn't really allow me to put them together.
I'm an absolute noob at arduino, and programming in general, and I've been told that the best way of achieving this would be to use two separate for loops nested inside of another loop.
So I'm taking baby steps to at least see if I can get the two for loops functioning individually, starting with the 'bar graph'. I started by doing a few lessons using the "knightrider" lights example, and I can get that working the way it's supposed to. I can add code to change the speed of the chase, add lights to extend the travel length, etc. So from there, I modified the sketch:
I took out the for loop that causes the chaser light to 'bounce back and forth", and now it only travels in one direction, repeatedly.
From there, I then attempted to modify the code in such a way that each previous light in the sequence actually stays on instead of only one light being on at a time. After doing this, the blue LEDs now behave like a bar graph. That is, they 'fill up'. The issue that I'm running into is that I'm trying to figure out how to get that to repeat indefinitely. Because at the moment, after the code is uploaded to the mega, the bar graph 'fills up' but then stops. No repeat.
In the grand scheme of things, I wanted it to behave like this:
-
The 14 blue LEDs (pins 2-15) each turn on consecutively and stay on until the last blue LED (pin 15) is activated. They then turn off and immediately repeat the cycle indefinitely.
-
Each time the blue LEDs loop back around and start over, I was hoping to use the first blue LED (pin 2) as a trigger to turn on (and off) each of the 4 red LEDS (we'll call them A,B,C,D on pins 16, 17, 18, and 19). In other words:
-Pin 2 activates the first LED in the bar graph, which also activates the LED A at pin 16.
-Pin 16 stays on for the duration of the 2-15 loop/fill up. Once the bar graph fills/illuminates fully, it turns off and begins the loop again.
-Pin 2 is activated a second time, once the loop begins, this time turning off LED A, and activating pin 17 (LED B). The bar graph fills up, and turns off.
-Pin 2 is activated a third time, starting the loop, turning off LED B, activating pin 18 (C). Bar graph fills up, and turns off.
-Same thing happens one more time. This time, pin 2 turns off pin 18, and activates pin 19. Bar graph fills up and turns off.
And I want that whole mess to repeat indefinitely, until I power it off.
Does that make sense?
I understand how a for loop works in the example of the chaser/knightrider. It's just transposing those concepts to fit what I'm trying to achieve. I'm too right-brained for my own good, it seems.
Can anyone shed some light on this? I could post my very remedial code if you need to see it.