Hello,
I have been using my arduino for two days so far and am very new to it.
One the of pre downloaded sample sketches in the arduino program is the bar=graph. I got it to blink the lights in ascending order, that is, one lights on and then turns off, light two goes on and then off, and three and so on. I am now wondering if there is a way to specify a range of values in order to get the entire sequence of lights that are allowed, based on the reading of a potentiometer, to blink on and off in harmony. I mean to write something
digitalWrite(ledPins[0 to thisPin], HIGH);
Is there any other way I can specify entire ranges of value to turn on and then off, or can I only do it in ascending or descending order using the "for" loop?
Thank you for answering this question while it may seem elementary.
There are 'low level' methods for turning on entire ports (up to 8 bits) at once but these will depend on the processor you are using. In Arduino C++ you use a for loop and the libraries map the digital pin to a port and bit number.
One could write a function that accepts an array, but in C++ one should also give the size of the array (or use a hardcoded fixed size)
That function has a for loop internally to go through the array.
There is a million and one complicated and tricky things that you "could" do.
The best policy is to keep it simple.
The simplest solution to the problem you posed, is
for ( int i = 0 ; i<= thisPin ; i++ ) digitalWrite( ledPins[i], HIGH );
The only reason you would want to do something more complicated than this, is if for some reason you could not
tolerate the microsecond delay that would arise between each LED being turned on.