Multiple LED's blink without delay
i have array of 11 pins. trying sequence going leds blink on , off outside in middle.
0 - - - - - - - - - 0
- 0 - - - - - - - 0 -
- - 0 - - - - - 0 - -
- - - 0 - - - 0 - - -
- - - - 0 - 0 - - - -
- - - - - 0 - - - - -
0 = led on.
i can delays coding individual pins manually.
i have been using blink without delay example.
the problem having led board using inverted
so high led's off , low led's on.
the problem every second led turning on 1 @ time , not blinking. once these on, other led's start blinking. not seem incrementing through arrays 1 pin @ time.
my code is:
0 - - - - - - - - - 0
- 0 - - - - - - - 0 -
- - 0 - - - - - 0 - -
- - - 0 - - - 0 - - -
- - - - 0 - 0 - - - -
- - - - - 0 - - - - -
0 = led on.
i can delays coding individual pins manually.
i have been using blink without delay example.
the problem having led board using inverted
so high led's off , low led's on.
the problem every second led turning on 1 @ time , not blinking. once these on, other led's start blinking. not seem incrementing through arrays 1 pin @ time.
my code is:
code: [select]
int index = 0;
int ledpins[] = {
9,8,7,6,5,4,3,2,14,15,16};
int ledstate = high;
unsigned long currentmillis = millis();
unsigned long previousmillis = millis();
long interval = 1000;
int x = 0;
int test1l[] = {
9,8,7,6,5};
int test1r[] = {
16,15,14,2,3};
void setup()
{
serial.begin(19200);
for(index = 0; index < 11; index++)
{
pinmode(ledpins[index], output);
}
for(int = 0; < 11; i++)
{
digitalwrite(ledpins[i], high);
}
}
void loop()
{
unsigned long currentmillis = millis();
analogwrite(11, 0);
analogwrite(12, 0);
analogwrite(13, 255);
if(currentmillis - previousmillis > interval)
{
previousmillis = currentmillis;
if (ledstate == high)
{
ledstate = low;
}
else
{
ledstate = high;
}
analogwrite(11, 0);
analogwrite(12, 0);
analogwrite(13, 255);
digitalwrite(test1l[x], ledstate);
digitalwrite(test1r[x], ledstate);
x++; //increment x pins
}
if(x > 4)
{
digitalwrite(4, ledstate); //blink middle led
x = 0;
}
}
simplified code bit, find 7 differences

code: (not tested) [select]
int ledpins[] = {
9,8,7,6,5,4,3,2,14,15,16};
unsigned long previousmillis = 0;
unsigned long interval = 1000;
int x = 0;
void setup()
{
serial.begin(19200);
for(int i= 0; < 11; i++)
{
pinmode(ledpins[i], output);
digitalwrite(ledpins[i], high);
}
}
void loop()
{
unsigned long currentmillis = millis();
if (currentmillis - previousmillis >= interval)
{
previousmillis = currentmillis;
// switch off
digitalwrite(ledpins[x], high); // left
digitalwrite(ledpins[9-x], high); // right
x++;
if (x == 4) x = 0;
// switch on
digitalwrite(ledpins[x], low); // left
digitalwrite(ledpins[9-x], low); // right
digitalwrite(4, !digitalread(4)); //invert middle led every step
}
}
Arduino Forum > Using Arduino > Programming Questions > Multiple LED's blink without delay
arduino
Comments
Post a Comment