# Trying to code a ws2812, I just need some help

**URL:** <https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272>\
**Category:** LEDs and Multiplexing\
**Created:** [May 26, 2022, 8:09pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272 "2022-05-26T20:09:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cherry\_tree](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@cherry\_tree](https://forum.arduino.cc/u/cherry_tree)\
**Post date:** [May 26, 2022, 8:09pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/1 "2022-05-26T20:09:41Z")

</div>

I've just started learning how to program with Arduino, so I don't know exactly what I'm doing 100% of the time. Currently I have a goal in mind

The one I'm working on is trying to get two colors to move across the led strip. Similar to the way movie lights move. This one I do have code for. It gets the idea across of what I want it to do, I just don't know how to connect the code to show up at the same time and how to get it to move.

```cpp
#include <FastLED.h>

#define DATA_PIN 2
#define NUM_LEDS 300
#define BRIGHTNESS 10
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB

// Define the array of leds
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 10

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop(){
  moving_three_led();
}
void moving_three_led(){
  for (int i=0; i<NUM_LEDS; i++){
    if ((i % 2) == 0){leds[i] = CRGB(255, 0, 90);}
    FastLED.show();
  }
  for (int i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB::Black;
    }
  for (int i=0; i<NUM_LEDS; i++){
    if ((i % 2) == 1){leds[i] = CRGB(0, 255, 190);}
    FastLED.show();
  }
    for (int i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB::Black;
    }
  }

```

Any help is appreciated

---

<div class="post-metadata">

**Author:** ![cherry\_tree](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@cherry\_tree](https://forum.arduino.cc/u/cherry_tree)\
**Post date:** [May 26, 2022, 8:10pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/2 "2022-05-26T20:10:35Z")

</div>

This is the example that I drew up

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/a/4/0/a40d05dd4cc692069327c9d0cd43286fc30b8084.jpeg)

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [May 27, 2022, 6:29pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/3 "2022-05-27T18:29:57Z")

</div>

```cpp
#include <FastLED.h>

#define DATA_PIN 2
#define NUM_LEDS 300
#define BRIGHTNESS 20
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB

// Define the array of leds
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 10

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
  static byte StartPoint = 0;
  moving_three_led(StartPoint);
  delay(500);
  StartPoint = (++StartPoint) % 3;
}
void moving_three_led(byte offset) {
  for (int i = offset; i < NUM_LEDS; i += 3) {
    leds[i] = CRGB(255, 0, 90);
  }
  for (int i = (offset + 1) % 3; i < NUM_LEDS; i += 3) {
    leds[i] = CRGB::Black;
  }
  for (int i = (offset + 2) % 3; i < NUM_LEDS; i += 3) {
    leds[i] = CRGB(0, 255, 190);
  }
  FastLED.show();
}

```

---

<div class="post-metadata">

**Author:** ![cherry\_tree](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@cherry\_tree](https://forum.arduino.cc/u/cherry_tree)\
**Post date:** [May 31, 2022, 5:52pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/4 "2022-05-31T17:52:08Z")

</div>

Thank you for the help. That's some code that I needed but didn't post about. I still haven't gotten the code that I wanted.

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [May 31, 2022, 6:24pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/5 "2022-05-31T18:24:27Z")

</div>

is this what you want?

```cpp
#include <FastLED.h>

#define DATA_PIN 2
#define NUM_LEDS 300
#define BRIGHTNESS 20
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB

// Define the array of leds
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 10

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
  static byte StartPoint = 0;
  moving_led(StartPoint);
  delay(500);
  StartPoint = (++StartPoint) % 2;
}
void moving_led(byte offset) {
  for (int i = 0; i < NUM_LEDS; i += 2) {
    leds[i+offset] = CRGB(255, 0, 90);
    leds[i+1-offset] = CRGB(0, 255, 190);
  }
  FastLED.show();
}

```

---

<div class="post-metadata">

**Author:** ![cherry\_tree](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@cherry\_tree](https://forum.arduino.cc/u/cherry_tree)\
**Post date:** [June 2, 2022, 3:42pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/6 "2022-06-02T15:42:24Z")

</div>

YES! Omg, thank you so much!

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [June 2, 2022, 4:07pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/7 "2022-06-02T16:07:14Z")

</div>

mark as solution

---

<div class="post-metadata">

**Author:** ![cherry\_tree](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@cherry\_tree](https://forum.arduino.cc/u/cherry_tree)\
**Post date:** [June 2, 2022, 4:18pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/8 "2022-06-02T16:18:33Z")

</div>

Ok! Thank you for the help through this process.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 29, 2022, 4:19pm UTC](https://forum.arduino.cc/t/trying-to-code-a-ws2812-i-just-need-some-help/996272/9 "2022-11-29T16:19:15Z")

</div>

Closed on November 29, 2022, 4:19pm UTC

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