Maker Pro
Maker Pro

Arduino: Controling LED Strip

CyberWizard

Sep 17, 2014
15
Joined
Sep 17, 2014
Messages
15
Hi there!

I'm new to arduino stuff and I'm still learning.
I had some experience programming ( Pascal, Visual Basic and C), at the moment i'm trying to make every led in a 10 LED Strip blink, and with the last LED blinks, perform the same action backwords ( from the last LED to the first).

I tried the following code but it aint working (it compiles, tested with 3 LEDs first):
Code:
int nPin;
void setup()
{
    // put your setup code here, to run once:
    for (nPin=31; nPin = 33; nPin++)
    {
        pinMode(nPin,OUTPUT);
    }
}

void loop()
{
    // Acende os LED's sequecialmente até a porta 10
    for (nPin=31; nPin=33; nPin++)
    {
        digitalWrite(nPin, HIGH);
        delay(250);
        digitalWrite(nPin, LOW);
    }
    // Acende os LED's sequencialmente até a porta 1
    for (nPin=33; nPin=31; nPin--)
   {
        digitalWrite(nPin, HIGH);
        delay(250);
        digitalWrite(nPin, LOW);
    }
}

It only lights one of the LEDs and it doesn't blink.
I'm using the wrong arduino ports? (Arduino DUE)
If the code is ok, guess there something wrong with the circuit. :p

(Edit by moderator to use CODE and /CODE tags and fix indentation -- KrisBlueNZ)
 
Last edited by a moderator:

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
What kind of LED strip are you using? Most are one of two kinds:

First kind lights all the LEDs that same. You cannot do what you want to do with that kind.

Second kind as individually addressable LEDs, and you have to send a code of 24 bits to each LED to set it's color. If you have this type, your code is nowhere near doing what it needs to.

Your code is writing in sequence to 3 ports (32, 32, 33). How is this supposed to control 10 LEDs. Are there 10 (or more) connections to your LED strip?

Please give us a link to the LED strip that you are using. Then maybe we can help you do what you want to do.

Bob
 

mikeee

Jan 25, 2015
5
Joined
Jan 25, 2015
Messages
5
In all three cases your for loop condition (the thing between the semicolons) is using the assignment operator instead of the less-than-or-equals operator which is <=.

This has the unfortunate effect of assigning the value on the right side to the variable, and returning the value of the assignment (which in all three cases will be a non-zero value and therefore be treated as 'true').

Change the single equals sign to <= (or >= when counting down) and you should see some more LEDs.
 

CyberWizard

Sep 17, 2014
15
Joined
Sep 17, 2014
Messages
15
In all three cases your for loop condition (the thing between the semicolons) is using the assignment operator instead of the less-than-or-equals operator which is <=.

This has the unfortunate effect of assigning the value on the right side to the variable, and returning the value of the assignment (which in all three cases will be a non-zero value and therefore be treated as 'true').

Change the single equals sign to <= (or >= when counting down) and you should see some more LEDs.


Ohh I see the problem there. I'm assigning 33 to nPin the first time it check the condition. LOL
 

CyberWizard

Sep 17, 2014
15
Joined
Sep 17, 2014
Messages
15
What kind of LED strip are you using? Most are one of two kinds:

First kind lights all the LEDs that same. You cannot do what you want to do with that kind.

Second kind as individually addressable LEDs, and you have to send a code of 24 bits to each LED to set it's color. If you have this type, your code is nowhere near doing what it needs to.

Your code is writing in sequence to 3 ports (32, 32, 33). How is this supposed to control 10 LEDs. Are there 10 (or more) connections to your LED strip?

Please give us a link to the LED strip that you are using. Then maybe we can help you do what you want to do.

Bob
Thanks for the reply Bob, please just ignore the term "LED Strip" its just 10 LED's, each has its own arduino port. I did state in my original post that i only tested with 3 LED's. I'll add the remaining 7 when those 3 are working :p
 
Top