Issue getting 2 led halos to run different animations from different pins

Hi,

I am VERY new the arduino and programming. Saying that, i am a fast learner of anything technical and i have already learned a lot and fixed a lot of the issues i started out with.

Sorry if i have posted this wrongly and i accept any help with my post if it is incorrect.

So here is my problem,
I am building a set of custom headlight for my car and all of the kits out there are either very expensive or are rubbish (sp110e, sp107e, etc, controllers).
So i decided to go the arduino route and so far i am enjoying it, i have had a lkot of success with some things, but then encountered problems, so i decided to go back to the start.

I am trying to run 2 slightly different animations from 1 arduino on 2 different WS2812b LED rings (halos).
I have successfully been able to get the 2 halos to run in different colours and from different pins on the arduino and i have been able to change between the animations (basically a single led moving around the ring either clockwise or anticlockwise).
The next thing i want to do is run the animation clockwise on 1 halo and anticlockwise on the other halo. I just cannot seen to get this to work after many hours of trying different things.

Would anyone be able to take a look at my code and either help a guy out by correcting it or point me in the right direction.

The following line of code seems to be the problem, to get the flow of the leds to go into reverse i can change the int value of white and green to 32 and set the last part to -1 instead of +1, but i cannot have one set as 0 and +1 and the other set as 32 and -1.

for (int White = 0, Green = 0; White < NUM_LED1, Green < NUM_LED2; White = White + 1, Green = Green + 1)

Below is the full sketch in a working state with both LED rings moving in a clockwise direction.

Many thanks in advance!

#include <FastLED.h>

// Moves a white dot around a ring of leds.

#define NUM_LED1 33
#define NUM_LED2 33


#define DATA_PIN 6
#define DATA_PINB 3

CRGB leds[NUM_LED1];
CRGB ledsB[NUM_LED2];



void setup() {

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LED1);
  FastLED.addLeds<WS2812B, DATA_PINB, GRB>(ledsB, NUM_LED2);

}

void loop() {

  {

    for (int White = 0, Green = 0; White < NUM_LED1, Green < NUM_LED2; White = White + 1, Green = Green + 1)


    {
      // Turn our current led on to white/green, then show the leds
      leds[White] = CRGB::White;
      ledsB[Green] = CRGB::Green;

      // Show the leds (only one of which is set to white/green, from above)
      FastLED.show();

      // Wait a little bit
      delay(25);

      // Turn our current led back to black for the next loop around
      leds[White] = CRGB::Black;
      ledsB[Green] = CRGB::Black;

    }

  }

}

OK, let’s now see the anticlockwise code.

For some reason i can either have one of the halos running in anticlockwise and the other one off without there being and issue when running it. Or I can have one running clockwise and one anticlockwise, but it seems to run and then pause for a bit and then run again.

First bit is with one running anticlockwise with the green ring commented out:

#include <FastLED.h>

// Moves a white dot around a ring of leds.

#define NUM_LED1 33
#define NUM_LED2 33


#define DATA_PIN 6
#define DATA_PINB 3

CRGB leds[NUM_LED1];
CRGB ledsB[NUM_LED2];



void setup() {

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LED1);
  FastLED.addLeds<WS2812B, DATA_PINB, GRB>(ledsB, NUM_LED2);

}

void loop() {

  {

    for (int White = 32, Green = 32; White < NUM_LED1, Green < NUM_LED2; White = White - 1, Green = Green - 1)


    {
      // Turn our current led on to white/green, then show the leds
      leds[White] = CRGB::White;
      //ledsB[Green] = CRGB::Green;

      // Show the leds (only one of which is set to white/green, from above)
      FastLED.show();

      // Wait a little bit
      delay(25);

      // Turn our current led back to black for the next loop around
      leds[White] = CRGB::Black;
      ledsB[Green] = CRGB::Black;

    }

  }

}

This second bit is one clockwise, one anticlockwise, but with a big pause between when it does each loop:

#include <FastLED.h>

// Moves a white dot around a ring of leds.

#define NUM_LED1 33
#define NUM_LED2 33


#define DATA_PIN 6
#define DATA_PINB 3

CRGB leds[NUM_LED1];
CRGB ledsB[NUM_LED2];



void setup() {

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LED1);
  FastLED.addLeds<WS2812B, DATA_PINB, GRB>(ledsB, NUM_LED2);

}

void loop() {

  {

    for (int White = 0, Green = 32; White < NUM_LED1, Green < NUM_LED2; White = White + 1, Green = Green - 1)


    {
      // Turn our current led on to white/green, then show the leds
      leds[White] = CRGB::White;
      ledsB[Green] = CRGB::Green;

      // Show the leds (only one of which is set to white/green, from above)
      FastLED.show();

      // Wait a little bit
      delay(25);

      // Turn our current led back to black for the next loop around
      leds[White] = CRGB::Black;
      ledsB[Green] = CRGB::Black;

    }

  }

}

Through perseverance and a lot of experimenting, i managed to get it working!

I’m going to paste my code below, if there is an easier way or a better way to do this, i would really welcome the feedback as it would help me learn a lot!

#include <FastLED.h>

// Moves a white dot around a ring of leds.

#define NUM_LED1 33
#define NUM_LED2 33


#define DATA_PIN 6
#define DATA_PINB 3

CRGB leds[NUM_LED1];
CRGB ledsB[NUM_LED2];


void setup() {

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LED1);
  FastLED.addLeds<WS2812B, DATA_PINB, GRB>(ledsB, NUM_LED2);

}

void loop() {
  //
  //  for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
  //    leds[i] = CRGB::Red;    // set our current dot to red
  //    FastLED.show();
  //    leds[i] = CRGB::Black;  // set our current dot to black before we continue
  //  }
  //}



  {



    for (int White = 0, Green = 32; White < NUM_LED1, Green < NUM_LED2; White++, Green--)
      // for (int White = 0, Green = 0; White < NUM_LED1, Green < NUM_LED2; White = White + 1, Green = Green + 1)

    {
      // Turn our current led on to white/green, then show the leds
      leds[White] = CRGB::White;
      ledsB[Green] = CRGB::Green;

      // Show the leds (only one of which is set to white/green, from above)
      FastLED.show();

      // Wait a little bit
      delay(10);

      // Turn our current led back to black for the next loop around
      leds[White] = CRGB::Black;
      ledsB[Green] = CRGB::Black;

      if (White >= 32)
      { White = -1;
      }
      else {
        ;
      }

      if (Green <= 0)
      { Green = 33;
      }
      else {
        ;
      }

    }

  }

}
  for (int i=0; i<NUM_LED1; i++)
    {
      // Turn our current led on to white/green, then show the leds
      leds[i] = CRGB::White;
      ledsB[NUM_LED1-i] = CRGB::Green;

      // Show the leds (only one of which is set to white/green, from above)
      FastLED.show();

      // Wait a little bit
      delay(10);

      // Turn our current led back to black for the next loop around
      leds[i] = CRGB::Black;
      ledsB[NUM_LED1-i] = CRGB::Black;
    }
  static byte currentLed = 0;
  static unsigned long lastUpdate = 0;
  const unsigned long updatePeriod = 10;

  if (millis() - lastUpdate >= updatePeriod)
    {

      if ( ++currentLed >= NUM_LED1) currentLed = 0;

      // Turn our current led on to white/green, then show the leds
      leds[currentLed] = CRGB::White;
      ledsB[NUM_LED1-currentLed] = CRGB::Green;

      // Show the leds (only one of which is set to white/green, from above)
      FastLED.show();

      // Turn our current led back to black for the next loop around
      leds[currentLed] = CRGB::Black;
      ledsB[NUM_LED1-currentLed] = CRGB::Black;

      lastUpdate += updatePeriod;
    }

I very much appreciate you going to the trouble to write out those bits of code for me! I will now study them so I can understand what everything does and then use what i learn for other patterns i am going to create.
The only issue with both of the pieces of code was that the first LED on the green ring would never light up. But i fixed this (maybe not the best way to fix it though) by slightly changing 2 lines in the code NUM_LED1-i-1 , I had to add the ‘-1’ to make it complete the loop on the green ring.
But again, Thanks for the help!!

void loop() {
  {
    static uint8_t hue = 0;
     
  for (int i=0; i<NUM_LED1; i++)
    {
      // Turn our current led on to white/green, then show the leds
      leds[i] = CRGB::White;
      ledsB[NUM_LED1-i-1] = CRGB::Green;

      // Show the leds (only one of which is set to white/green, from above)
      FastLED.show();

      // Wait a little bit
      delay(10);

      // Turn our current led back to black for the next loop around
      leds[i] = CRGB::Black;
      ledsB[NUM_LED1-i-1] = CRGB::Black;
    }
  }
}

I had to add the ‘-1’ to make it complete the loop

Good spot, I should have got that right!

The second version I posted is better, it does not use delay().

May I ask if you can link the full final correct working sketch, I was peaceing it together and did get it to parts to wurk but not whit the final changes.
I've been trying implant your idea in the cololpalette sketch don't know if I'm allowed to post my version or if that would be taking over your topic and be rude