2- Neopixel jewels running opposite directions

Thread Starter

Mark1015

Joined May 15, 2020
20
I am having issues with the attached sketch. I want one jewel to be flashing clockwise (Led 0-6) and the other counterclockwise (led 13-7). I have tried 2 method. connected in series to use 1 pin on board and connected to separate pins onboard. The current sketch rotates both in the clockwise direction. I am at a loss. I believe the main issue is in the "void setup" I may need to do some work in the loop as well

Star Trek Bussards:
//=======for the Neopixel Jewel=========

#include <FastLED.h>// include library
#define NUM_LEDS 7 // number of leds
#define DATA_PIN 5 //signal pin of board
#define DATA_PIN2 3
#define MASTER_BRIGHTNESS 50
CRGB leds[NUM_LEDS];//setup individual clockwise led array
CRGB ledsR[NUM_LEDS];//setup individual counterclockwise led array



//=======for the Neopixel========
const unsigned long nacOnTime = 100; //each pixel on time
const unsigned long nacOffTime = 50; //each pixel off time
unsigned long nacInterval = nacOffTime;
unsigned long nacPreviousMillis;
unsigned long currentMillis = millis();
bool nacState;
int nacCount;

CRGB fixedColor[NUM_LEDS] =
{
  CRGB::Red,//led 0
  CRGB::Blue,//led 1
  CRGB::Yellow,//led 2
  CRGB::Green,//led 3
  CRGB::Orange,//led 4
  CRGB::Magenta,//led 5
  CRGB::Violet,//led 6
};

CRGB fixedColor2[NUM_LEDS] =
{
  CRGB::Red,//led 0
  CRGB::Blue,//led 1
  CRGB::Yellow,//led 2
  CRGB::Green,//led 3
  CRGB::Orange,//led 4
  CRGB::Magenta,//led 5
  CRGB::Violet,//led 6
};


void setup() {

  //  FastLED.setBrightness(MASTER_BRIGHTNESS);   // full brighness is better for Wokwi
  // start the strip and blank it out
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); //declare first LED strip
  FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds, NUM_LEDS); //declare first LED strip
  //Select led colors. these will not require random changing
  for ( int i = 0; i < NUM_LEDS; i++) {
    CRGB ledsR[NUM_LEDS - 1 - i] = leds[i];
    leds[i] = fixedColor[i];
    //ledsR[i]= fixedColor2[i]; (this line caused the full strips to light and stay on)
  }

  FastLED.show();
  delay( 2000);
  FastLED.clear();
}

void loop() {
  currentMillis = millis();
  NacLed();
}

// not sure where to go here
// i want pixel zero to be high for 100ms-low for 50ms, pixel 1 hinh for 100ms-low for 50ms etc.
// each pixel having a set indivdual color
void NacLed()
{
  if ( currentMillis - nacPreviousMillis >= nacInterval)
  {
    nacPreviousMillis = currentMillis;

    if ( nacState)
    {
      // Turn the led off by making it black.
      leds[nacCount] = CRGB::Black;

      nacState = false;
      nacInterval = nacOffTime;

      // Done with this led, set the next led
      nacCount++;
      if ( nacCount >= NUM_LEDS)
        nacCount = 0;
    }
    else
    {
      leds[nacCount] = fixedColor[nacCount];  // set this led to its own color
      nacState = true;
      nacInterval = nacOnTime;
    }
    FastLED.show();
  }
}
 

Thread Starter

Mark1015

Joined May 15, 2020
20
I have read through that. There is a section that uses “direction”. I am using the FastLED library as it appears more friendly with millis timing. I am new at this please be patient .the code posted will eventually be in a larger sketch that needs non blocking timing
 

MrSalts

Joined Apr 2, 2020
534
You have to fill the buffer of the counter clockwise buffer in reverse order before pushing it into the neopixels with a "display()" command or what ever the fastLED library uses.
 

Thread Starter

Mark1015

Joined May 15, 2020
20
You have to fill the buffer of the counter clockwise buffer in reverse order before pushing it into the neopixels with a "display()" command or what ever the fastLED library uses.
This is the line that is supposed to reverse the order. However I am not sure what to do to call the ledsR to function with the millis
Code:
CRGB ledsR[NUM_LEDS - 1 - i] = leds[i];
 
Top