1

Please help. I am learning a lot about Arduino. Most all in lightning. I am a newbie. I play with nano and LED ws2812 and use fastled library.

What ask is to make effect like fill effect. For example with larson scanner/chaser.

for (int i = 0; i<NUM_LEDS; i++)
{
  leds[i]=CRGB::Red;
  FastLED.show();
  leds[i]=CRGB::Black;
  delay(50);
}

From that code above how to make LED stop and lit up and loop again and stop and lit up. I want every LED stop the LED lit up even LED looping start again from first LED. It like this:

10000 01000 00100 00010 00001 10001 01001 00101 00011 10011 01011 00111 10111 01111 11111

5
  • 2
    i see no code above – jsotola Aug 10 '19 at 18:09
  • 1
    There's code - I edited it to make it look better / visible. – st2000 Aug 10 '19 at 18:22
  • 1
    I really don't understand your problem description. It seems, that English is not your native language. Maybe you can write a better description or ask someone to help you with it. We need to understand the problem, to be able to help you. – chrisl Aug 10 '19 at 18:22
  • 1
    Agree w/@chrisl, there is no "I have this problem" in the post. Assuming you are not seeing a lit LED traveling down the line of LEDs, try swapping the "delay" line of code w/the line above it. – st2000 Aug 10 '19 at 18:27
  • yes you right, iam not native english,iam indonesia.. sorry for my bad english and wrong title.. :).. but thank you all for advice.. i already have answer from @michel keijzers.. – Nitta Devy Aug 12 '19 at 18:34
0

You need two counter for this, one to keep track of how far the LED bar is filled, and one about the current 'running' LED to eventually 'touch' the LEDs which are already moved to the right.

Every led (currentLed) will run from index 0 until the last filled index, while the last filled index is decreased with 1 after every loop.

(note: I haven't checked the code).

// Fill from the right, thus count backwards.
for (int filledLedIndex = NUM_LEDS; filledLed >= 0; filledLed--)
{
   // Now let a LED run from 0 upto filedLedIndex;
   for (int currentLed = 0; currentLed < filledLedIndex)
   {
      // Make previous LED black
      if (currentLed > 0)
      {
         leds[i - 1] = CRGB::Black;
      }

      // Make current LED red
      leds[i] = CRGB::Red;

      // Show.
      FastLED.show();
      delay(50);
   }
}

// Clear all LEDs.
for (int led = 0; led < NUM_LEDS; led++)
{
    leds[i] = CRGB::Black;
}

FastLED.show();
delay(50);
2
  • thanks you a lot.. from your advice n little edit for my project and it finally work fine.. – Nitta Devy Aug 12 '19 at 18:36
  • but how to write right code for [code] for (int i = 0; i > y; AND i < x; i++) [/code] – Nitta Devy Aug 12 '19 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.