Connect with us

Arduino: Controling LED Strip

Discussion in 'Microcontrollers, Programming and IoT' started by CyberWizard, Feb 17, 2015.

Scroll to continue with content
  1. CyberWizard

    CyberWizard

    15
    0
    Sep 17, 2014
    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: Feb 17, 2015
  2. BobK

    BobK

    7,682
    1,688
    Jan 5, 2010
    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
     
  3. mikeee

    mikeee

    5
    1
    Jan 25, 2015
    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.
     
    KrisBlueNZ likes this.
  4. CyberWizard

    CyberWizard

    15
    0
    Sep 17, 2014

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

    CyberWizard

    15
    0
    Sep 17, 2014
    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
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-