Need help with coding , WS2818 using Arduino nano

So I was trying to send pulse or a wave of light from one end to another on ws2812 led strip, everytime a button is pressed using Arduino nano.
I got it working but I was only able to send one wave at a time, I could only send another wave once the first one has reached the other end. But after struggling for a day I managed to get it to work by modifying codes from similiar projects over internet.
But now my problem is that the wave is moving quite slow and no matter wat i try I can't get it to move faster. Please help!!

Hello @xenomatrix -

Would you replace the picture/image of your IDE with the code text? Be sure to use the < CODE > button to paste the code into a code block.

Can you also show a wiring diagram?

This works (your button press is a "knock" threshold above 800 (out of 0 to 1023)

Move FastLED.show() outside the for() loop... that is to say, change this:

  for (int i = NUM_LEDS - 1; i > 0; i--) {
    leds[i] = leds[i - 1];
    FastLED.show(); // sends a command to all pixels to change ONE pixel
  }

to this...

  for (int i = NUM_LEDS - 1; i > 0; i--) {
    leds[i] = leds[i - 1];
  }
  FastLED.show(); // sends a command to all pixels to change all pixels
1 Like

@xenomatrix i can't copy your sketch so i wrote my:

#include <FastLED.h>
#define NUM_LEDS 100
FASTLED_USING_NAMESPACE
CRGBArray<NUM_LEDS> leds;
#define LED_Out_pin A0

void setup() {
  pinMode(2, INPUT_PULLUP); // arduino uno, nano, mini, mega
  FastLED.addLeds<WS2811, LED_Out_pin, RGB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(255);
  attachInterrupt(digitalPinToInterrupt(2), gotPulse, FALLING);
}

void gotPulse() {
  PIND |= 8;
}

void loop() {
  for (int i = NUM_LEDS - 1; i > 0; i--) leds[i] = leds[i - 1];

  if (PIND & 8) {
    leds[0] = CHSV(random(0, 11) * 25 + 5, 255, 255);
    PIND |= 8;
  }
  else leds[0].nscale8(150);

  FastLED.show();
  FastLED.delay(20);
}

Yes, you (anyone) can copy the sketch. It was legible. You will note that the "show()" function was after every step in the loop rather than at the end of the loop. That is the point of my post, "Move the "show()" outside the loop.

Typing it is not copying :wink: OCR is not copying :wink:

Yes it is. The action is called "transcription." Secretaries did this all day long at 90WPM. I can only manage 45wpm... but I can also fix daisywheel printers and configure the router.

I "transcribed" the OP code and ran it in my "l a b o r a t o r y" where I found the misplaced FastLED.show().

Sorry about not not sharing the code as in text, it was in my laptop and I was just wrapping up while checking for ideas on my phone so I just clicked a picture and uploaded :sweat_smile:. You guys are awesome. I didn't expected to get a reply so soon :joy:
I'll check and update. If that works
Thank you so much.

1 Like

Worked like a charm bro, that was so silly. I actually dint even knew if that matters😅

1 Like

(Psst... you might click that "solution" button on the post #2 that turned out to be your solution, just sayin', it's only polite :wink: )

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.