0

NeoPixel class for faders and transistions
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

NeoPixel class for faders and transistions

by splatten on Sat Nov 22, 2014 5:06 pm

I have created a library called 'clsFader', this is a class derived from the 'Adafruit_NeoPixel' object. I used a NeoPixel ring with 24 RGB LED's to develop this library with an Arduino Uno. If you have a different sized ring, just change the NUM_OF_PIXELS definition. You will need the Adafruit_NeoPixel library. To try this out, copy the code from the sections below. Create a sketch named ring-demo and paste the following into it:
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#include <clsFader.h>

#define PIN                   6
#define NUM_OF_PIXELS         24
#define FADER_INC             8
#define FADER_STEPS           255
//Create fader strip
clsFader objStrip = clsFader(NUM_OF_PIXELS, PIN, NEO_RGB + NEO_KHZ800);

uint32_t aryu32colors[] = { 0xffffff, 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0x00ffff, 0xff00ff };
uint8_t aryu8Index[NUM_OF_PIXELS];


void nextColors(clsFader* pFader, uint8_t u8Pixel) {
//Set the current transition as the new initial colour
  pFader->setInitialRGB(aryu32colors[aryu8Index[u8Pixel]], u8Pixel);
//Generate a new transition colour
  if ( ++aryu8Index[u8Pixel] >= (sizeof(aryu32colors) / sizeof(aryu32colors[0])) ) {
    aryu8Index[u8Pixel] = 0;
  }
  pFader->setTransitionRGB(aryu32colors[aryu8Index[u8Pixel]], u8Pixel);
}

void setup() {
  memset(aryu8Index, 0, sizeof(aryu8Index));
  Serial.begin(9600);
//Set-up the faders
  objStrip.setStepIncrement(FADER_INC);
  objStrip.setSteps(FADER_STEPS);
  objStrip.setInitialRGB(0x00, 0x00, 0x00);
  objStrip.setTransitionRGB(aryu32colors[aryu8Index[0]]);
  objStrip.setCallback(nextColors);
  objStrip.setLoopState();
  objStrip.setRunningState();
  objStrip.begin();
  objStrip.show();
}

void loop() {
//Service the faders 
  objStrip.fade();
}


Now to create the library, create a folder in your 'libraries' folder called 'clsFader', on my system it is:
D:\Program Files (x86)\Arduino\libraries

Create two files, clsFader.h
Code: Select all | TOGGLE FULL SIZE
/**
 * File:
 *  clsFader.h
 * 
 * Notes:
 *  This file contains the prototypes for the classes:
 *    'clsFader'
 *******************************************************************************
 * Class:           
 *  clsFader
 *       
 * Members:
 *  mpCallback        Function to perform after transition
 *  mpPixel           Pointer to addition information for each pixel
 *    fltIncR           Increment per iteration for red
 *    fltIncG           Increment per iteration for green
 *    fltIncB           Increment per iteration for blue
 *    u16Step           The step number in the fader
 *    u32InitialRGB     The combine RGB 'initial' colour
 *    u32TransitionRGB  The combine RGB 'transition' colour
 *    u8InitialR        Initial red component
 *    u8InitialG        Initial green component
 *    u8InitialB        Initial blue component
 *    u8TransitionR     Transition red component         
 *    u8TransitionG     Transition green component
 *    u8TransitionB     Transition blue component
 *    u8Steps           Number of steps for the fade transition
 *    uComplete         1=Transition complete 
 *    uLoop             1=Loop
 *    uRunning          1=Running
 *    uStop             1=Stop
 *  mu16Delay         The delay factor 1 to 32768, 0 = no delay
 *  mu16DelayCtr      The count down delay counter     
 *  mu8NumPixels      Static:Number of pixels to manage             
 *  mu8StepInc        Step size
 *
 * Methods:
 *  clsFader          Constructor
 *  calculate         Works out fader internals
 *  fade              Iterates the fade to the next step in the sequence           
 *  findColor         Gets the colour at the specified step
 *  getInitialRGB     Gets the initial RGB colour
 *  getLoop           Gets the loop flag for the specified pixel
 *  getRunningStatus  Gets the running status flag
 *  getStep           Gets the current step
 *  getSteps          Gets the total number of steps
 *  getTransitionRGB  Gets the transition RGB colour
 *  setCallback       Sets the call-back to call when fade transision completes               
 *  setDelay          Sets the delay factor between fade iterations
 *  setLoopState      Sets the loop state for a pixel fader       
 *  setRunningState   Sets the running state for a pixel fader       
 *  setInitialRGB     Sets the initial RGB colour components
 *  setLoopState      Sets the state of the loop flag
 *  setRunningState   Sets the running flag
 *  setStepIncrement  Sets the step increment size   
 *  setTransitionRGB  Sets the transition RGB colour components
 *  setStep           Sets the step number
 *  setSteps          Sets the number of steps between the from and to colours
 *******************************************************************************
 * History:
 *  2014/11/12 Written by Simon Platten
 */
#ifndef CLSFADER_H
  #define CLSFADER_H

  #include <Arduino.h>
  #include "../Adafruit_NeoPixel/Adafruit_NeoPixel.h"

typedef struct {
  float    fltIncR,           //Increment per iteration for red
           fltIncG,           //Increment per iteration for green
           fltIncB;           //Increment per iteration for blue
  uint16_t u16Step;           //The step number in the fader
  uint32_t u32InitialRGB,     //The combine RGB 'initial' colour
           u32TransitionRGB;  //The combine RGB 'transition' colour
  uint8_t  u8InitialR,        //Initial red component
           u8InitialG,        //Initial green component
           u8InitialB,        //Initial blue component
           u8TransitionR,     //Transition red component         
           u8TransitionG,     //Transition green component
           u8TransitionB,     //Transition blue component
           u8Steps;           //Number of steps for fade transition fade           
//Flags                     
  unsigned uComplete  : 1;    //Indicates when transition complete
  unsigned uLoop      : 1;    //Loop
  unsigned uRunning   : 1;    //Running fader status
  unsigned uStop      : 1;    //Stop fader from running
} perPixelDef;
 
class clsFader: public Adafruit_NeoPixel {
private:
  void (*mpCallback)(clsFader*, uint8_t);//Function to perform after transition         
  perPixelDef* mpPixel;       //Pointer to addition information for each pixel
  uint8_t   mu8StepInc;       //Step size
  uint16_t  mu16Delay,        //The delay factor 1 to 255, 0 = no delay
            mu16DelayCtr;     //Count down delay counter 
//Works out fader internals
  void  calculate(perPixelDef* pPixel);
  void  calculate(int8_t s8Pixel);
//Gets the colour at the specified step 
  uint32_t findColor(uint8_t u8Pixel);
           
public:
//Function prototypes
//Constructor
  clsFader(uint16_t n, uint8_t p=6, uint8_t t=NEO_GRB + NEO_KHZ800);
//Iterates the fade to the next step in the sequence 
  void     fade(void);
//Gets the initial RGB colour 
  uint32_t getInitialRGB(uint8_t u8Pixel);
//Gets the loop flag for the specified pixel 
  unsigned getLoop(uint8_t u8Pixel);
//Gets the running status flag 
  unsigned getRunningStatus(uint8_t u8Pixel);
//Gets the current step 
  uint16_t getStep(uint8_t u8Pixel);
//Gets the total number of steps 
  uint8_t  getSteps(uint8_t u8Pixel);
//Gets the transition RGB colour 
  uint32_t getTransitionRGB(uint8_t u8Pixel);
//Sets the call-back to call when fade transision completes 
  void     setCallback(void (*pCallback)(clsFader* p, uint8_t u8Pixel));
//Sets the delay factor between fade iterations 
  void     setDelay(uint16_t u16Delay);
//Sets the initial RGB colour components
  void     setInitialRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                           int8_t s8Pixel = -1);
//Sets the intial RGB colour 
  void     setInitialRGB(uint32_t u32RGB, int8_t s8Pixel = -1); 
//Sets the state of the loop flag 
  void     setLoopState(boolean blnState = true, int8_t s8Pixel = -1);
//Sets the running flag   
  void     setRunningState(boolean blnState = true, int8_t s8Pixel = -1);
//Sets the step increment size 
  void     setStepIncrement(uint8_t u8StepInc);
//Sets the final RGB colour components
  void     setTransitionRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                           int8_t s8Pixel = -1);
//Sets the transition RGB colour 
  void     setTransitionRGB(uint32_t u32RG, int8_t s8Pixel = -1); 
//Sets the step number
  void     setStep(uint16_t u16Step, int8_t s8Pixel = -1);
//Sets the number of steps between the from and to colours
  void     setSteps(uint8_t u8Steps, int8_t s8Pixel = -1);
};

#endif // CLSFADER_H           


and clsFader.cpp
Code: Select all | TOGGLE FULL SIZE
/**
 * File:
 *  clsFader.cpp
 * 
 * Notes:
 *  This file contains the implementation of the class 'clsFader'
 *   
 * History:
 *  2014/11/12 Written by Simon Platten
 */
/**
* Default constructor
*/
#include <Math.h>
#include <clsFader.h>

#define DEBUG_INFO 1
/*******************************************************************************
 * Default constructor
 ******************************************************************************/
clsFader::clsFader(uint16_t n, uint8_t p, uint8_t t)
                                                  : Adafruit_NeoPixel(n, p, t) {
  if ( n > 0 ) {
    mpPixel = new perPixelDef[n];
   
    for( uint8_t p=0; p<n; p++ ) {
      memset(&mpPixel[p], 0, sizeof(perPixelDef));
    }
  }
  setStepIncrement(1);
  setCallback(NULL);
  setSteps(255);
  setDelay(0);
}
/**
 * calculate
 * Parameters:
 *  pPixel, the pixel definition   
 * Works out fader internal for the passed pixel
 */ 
void clsFader::calculate(perPixelDef* pPixel) {
//Combine the 'initial' components 
  pPixel->u32InitialRGB = (((uint32_t)pPixel->u8InitialR) << 0x10) |
                          (((uint32_t)pPixel->u8InitialG) << 0x08) |
                           ((uint32_t)pPixel->u8InitialB);
//Combine the 'transition' components 
  pPixel->u32TransitionRGB = (((uint32_t)pPixel->u8TransitionR) << 0x10) |
                             (((uint32_t)pPixel->u8TransitionG) << 0x08) |
                              ((uint32_t)pPixel->u8TransitionB);
// Work out the transition colours for the steps between min and max
  uint8_t u8DiffR = abs(pPixel->u8InitialR - pPixel->u8TransitionR),
          u8DiffG = abs(pPixel->u8InitialG - pPixel->u8TransitionG),
          u8DiffB = abs(pPixel->u8InitialB - pPixel->u8TransitionB);
  pPixel->fltIncR = (float)u8DiffR / (float)pPixel->u8Steps;
  pPixel->fltIncG = (float)u8DiffG / (float)pPixel->u8Steps;
  pPixel->fltIncB = (float)u8DiffB / (float)pPixel->u8Steps;
//Reset the step number for each pixel                       
  pPixel->u16Step = 0; 
}
/**
 * calculate
 * Parameters:
 *  u8Pixel, the pixel number base 0 
 * Works out fader internals
 */ 
void clsFader::calculate(int8_t s8Pixel) {
  perPixelDef* pPixel;
 
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      calculate(&mpPixel[u8Pixel]);
    }
  } else if ( s8Pixel < numPixels() ) {
    calculate(&mpPixel[s8Pixel]);
  }
}
/**
 * fade
 * Services the fader, must be started first
 */   
void clsFader::fade(void) {
  if ( mu16DelayCtr > 0 ) {
//Delay between fade iterations, not 0 yet, return 
    mu16DelayCtr--;
    return;
  } else {
    mu16DelayCtr = mu16Delay;
  }
  for( uint8_t f=0; f<numPixels(); f++ ) {
    perPixelDef* pPixel = &mpPixel[f];
   
    if ( !pPixel->uRunning ) {
      continue;
    }
    uint32_t u32Color = findColor(f);
    setPixelColor(f, u32Color);
   
    if ( pPixel->uComplete ) {
      pPixel->uComplete = false;
     
      if ( mpCallback != NULL ) {
        (*mpCallback)(this, f);
      }
//Work out the internals
      calculate(-1);     
    }
    if ( pPixel->uStop ) {
      pPixel->uRunning = false;
      continue;
    }
#ifdef DEBUG_INFO   
    if ( f == 0 ) {
      Serial.print("pixel[");
      Serial.print(f);
      Serial.print("] initialRGB[");
      Serial.print(pPixel->u32InitialRGB, HEX);
      Serial.print("] transitionRGB[");
      Serial.print(pPixel->u32TransitionRGB, HEX);
      Serial.print("] step[");
      Serial.print(pPixel->u16Step);
      Serial.print("] steps[");
      Serial.print(pPixel->u8Steps);
      Serial.print("] inc[");
      Serial.print(mu8StepInc);
      Serial.print("] color[");
      Serial.print(u32Color, HEX);
      Serial.print("] loop[");
      Serial.print(pPixel->uLoop);
      Serial.print("]\n");
    }
#endif   
    pPixel->u16Step += mu8StepInc;
       
    if ( pPixel->u16Step >= pPixel->u8Steps ) {
      if ( pPixel->uLoop ) {
        pPixel->u16Step = 0;
      } else {
        pPixel->u16Step = 255;
        pPixel->uStop = true;
      }
      pPixel->uComplete = true;
    }
  }
  show();
}
/**
 * findColor
 * Parameters:
 *  u8Pixel, the index of the pixel 0 to n
 * Returns:
 *  The colour at the specfied step
 */       
uint32_t clsFader::findColor(uint8_t u8Pixel) {
  perPixelDef* pPixel = &mpPixel[u8Pixel];
 
  if ( pPixel->u16Step > pPixel->u8Steps ) {
    pPixel->u16Step = pPixel->u8Steps;
  }   
  uint8_t u8R = (uint8_t)((float)pPixel->u16Step * pPixel->fltIncR) & 0xff,
          u8G = (uint8_t)((float)pPixel->u16Step * pPixel->fltIncG) & 0xff,
          u8B = (uint8_t)((float)pPixel->u16Step * pPixel->fltIncB) & 0xff;
  uint32_t u32RGB = pPixel->u32InitialRGB ^ (((uint32_t)u8R << 0x10) |
                                             ((uint32_t)u8G << 0x08) |
                                             ((uint32_t)u8B));
  return u32RGB;
}
/**
 * getInitialRGB
 * Parameters:
 *  u8Pixel, the index of the pixel 0 to n
 * Returns: The initial RGB colour
 */ 
uint32_t clsFader::getInitialRGB(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u32InitialRGB;
  }
  return 0;
}
/**
 * getLoop
 * Parameters:
 *  u8Pixel, the pixel to check 
 * Returns: the state of the loop flag for the specified pixel
 */ 
unsigned clsFader::getLoop(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].uLoop;
  }
  return 0;
}
/**
 * getRunningStatus
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: the running status flag
 */   
unsigned clsFader::getRunningStatus(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].uRunning;
  }
  return 0;
}
/**
 * getStep
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: the current step
 */ 
uint16_t clsFader::getStep(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u16Step;
  }
  return 0;
}
/**
 * getSteps
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: the total number of steps
 */ 
uint8_t clsFader::getSteps(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u8Steps;
  }
  return 0;
}
/**
 * getTransitionRGB
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: The transition RGB colour
 */   
uint32_t clsFader::getTransitionRGB(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u32TransitionRGB;
  }
  return 0;
}
/**
 * setCallback
 * Parameters:
 *  pCallback, pointer to function to call when transition completes
 */   
void clsFader::setCallback(void (*pCallback)(clsFader* p, uint8_t u8Pixel)) {
  mpCallback = pCallback;
}
/**
 * setDelay
 * Parameters:
 *  u8Delay, the delay to set between fade iterations 1 to 255, 0 = no delay
 */   
void clsFader::setDelay(uint16_t u16Delay) {
  mu16Delay = mu16DelayCtr = u16Delay;
}
/**
 * setInitialRGB
 * Parameters:
 *  u8Red, the red component 0 to 255
 *  u8Green, the green component 0 to 255
 *  u8Blue, the blue component 0 to 255
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setInitialRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                               int8_t s8Pixel) {
  perPixelDef* pPixel;
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      pPixel = &mpPixel[u8Pixel];
      pPixel->u8InitialR = u8Red;
      pPixel->u8InitialG = u8Green;
      pPixel->u8InitialB = u8Blue;
    }
  } else if ( s8Pixel < numPixels() ) { 
      pPixel = &mpPixel[s8Pixel];
      pPixel->u8InitialR = u8Red;
      pPixel->u8InitialG = u8Green;
      pPixel->u8InitialB = u8Blue;
  }
}
/**
 * setInitialRGB
 * Parameters:
 *  u32RGB, the Red, Green and Blue 32bit colour value
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setInitialRGB(uint32_t u32RGB, int8_t s8Pixel) {
  setInitialRGB(((u32RGB >> 0x10) & 0xff),
                ((u32RGB >> 0x08) & 0xff),
                (u32RGB & 0xff), s8Pixel);

/**
 * setLoopState
 * Parameters:
 *  blnState, optional, true=fadeout, false=fadein 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 */ 
void clsFader::setLoopState(boolean blnState, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      mpPixel[u8Pixel].uLoop = (blnState == true) ? 1 : 0;
    }
  } else if ( s8Pixel < numPixels() ) { 
    mpPixel[s8Pixel].uLoop = (blnState == true) ? 1 : 0;
  }
}
/**
 * setRunningState
 * Parameters:
 *  blnState, optional, true=fadeout, false=fadein 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 */   
void clsFader::setRunningState(boolean blnState, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      mpPixel[u8Pixel].uRunning = (blnState == true) ? 1 : 0;
    }
  } else if ( s8Pixel < numPixels() ) { 
    mpPixel[s8Pixel].uRunning = (blnState == true) ? 1 : 0;
  }
  if ( blnState == true ) {
//Work out the internals
    calculate(-1);
  }           
}
/**
 * setTransitionRGB
 * Parameters:
 *  u8Red, the red component 0 to 255
 *  u8Green, the green component 0 to 255
 *  u8Blue, the blue component 0 to 255
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setTransitionRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                               int8_t s8Pixel) {
  perPixelDef* pPixel;
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      pPixel = &mpPixel[u8Pixel];
      pPixel->u8TransitionR = u8Red;
      pPixel->u8TransitionG = u8Green;
      pPixel->u8TransitionB = u8Blue;
    }
  } else if ( s8Pixel < numPixels() ) { 
      pPixel = &mpPixel[s8Pixel];
      pPixel->u8TransitionR = u8Red;
      pPixel->u8TransitionG = u8Green;
      pPixel->u8TransitionB = u8Blue;
  }
}
/**
 * setTransitionRGB
 * Parameters:
 *  u32RGB, the Red, Green and Blue 32bit colour value
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setTransitionRGB(uint32_t u32RGB, int8_t s8Pixel) {
  setTransitionRGB(((u32RGB >> 0x10) & 0xff),
                   ((u32RGB >> 0x08) & 0xff),
                    (u32RGB & 0xff), s8Pixel);

/**
 * setStepIncrement
 * Parameters:
 *  u8StepInc, the step increment size, min 1 
 */ 
void clsFader::setStepIncrement(uint8_t u8StepInc) {
  if ( u8StepInc > 0 ) {
    mu8StepInc = u8StepInc;
  }
}
/**
 * setStep
 * Paramters:
 *  u16Step, the step number to use 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 * Sets the step number
 */ 
void clsFader::setStep(uint16_t u16Step, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      if ( u16Step >= mpPixel[u8Pixel].u8Steps ) {
        u16Step =0;
      }
      mpPixel[u8Pixel].u16Step = u16Step;
    }
  } else if ( s8Pixel < numPixels() ) {
    mpPixel[s8Pixel].u16Step = u16Step; 
  }
}
/**
 * setSteps
 * Paramters:
 *  u8Steps, the number of steps to use 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 * Sets the number of steps between the transitions 0 to 255
 */ 
void clsFader::setSteps(uint8_t u8Steps, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      mpPixel[u8Pixel].u8Steps = max(1, u8Steps);
    }
  } else if ( s8Pixel < numPixels() ) { 
    mpPixel[s8Pixel].u8Steps = max(1, u8Steps);
  }
}


There are various settings you can play with, there is one issue with the library that I would like advice/assistance with, when the fade is complete and it transitions to the next fade via the callback there is often a flicker or a random flash of colour on the ring, I'm not sure why or what is causing this.

Please feel free to use this library for your own projects, however please keep the comment headers as they are.

Thank you,
Sy
Last edited by splatten on Sat Dec 06, 2014 12:20 pm, edited 1 time in total.

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel faders

by splatten on Sun Nov 23, 2014 8:44 am

All issues now resolved!

ring-demo.ino:
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#include <clsFader.h>

#define PIN                   6
#define NUM_OF_PIXELS         24
#define FADER_INC             1
#define FADER_STEPS           255
//Create fader strip
clsFader objStrip = clsFader(NUM_OF_PIXELS, PIN, NEO_RGB + NEO_KHZ800);

uint32_t aryu32colors[] = { 0xffffff, 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0x00ffff, 0xff00ff };
uint8_t aryu8Index[NUM_OF_PIXELS];


void nextColors(clsFader* pFader, uint8_t u8Pixel) {
//Set the current transition as the new initial colour
  pFader->setInitialRGB(aryu32colors[aryu8Index[u8Pixel]], u8Pixel);
//Generate a new transition colour
  if ( ++aryu8Index[u8Pixel] >= (sizeof(aryu32colors) / sizeof(aryu32colors[0])) ) {
    aryu8Index[u8Pixel] = 0;
  }
  pFader->setTransitionRGB(aryu32colors[aryu8Index[u8Pixel]], u8Pixel);
}

void setup() {
  memset(aryu8Index, 0, sizeof(aryu8Index));
  Serial.begin(9600);
//Set-up the faders
  objStrip.setStepIncrement(FADER_INC);
  objStrip.setSteps(FADER_STEPS);
  objStrip.setInitialRGB(0x00, 0x00, 0x00);
  objStrip.setTransitionRGB(aryu32colors[aryu8Index[0]]);
//  objStrip.setSteps(10);
//  objStrip.setDelay(10000);
  objStrip.setCallback(nextColors);
//  objStrip.setLoopState();
  objStrip.setRunningState();
  objStrip.begin();
  objStrip.show();
}

void loop() {
//Service the faders 
  objStrip.fade();
}


clsFader.h:
Code: Select all | TOGGLE FULL SIZE
/**
 * File:
 *  clsFader.h
 * 
 * Notes:
 *  This file contains the prototypes for the classes:
 *    'clsFader'
 *******************************************************************************
 * Class:           
 *  clsFader
 *       
 * Members:
 *  mpCallback        Function to perform after transition
 *  mpPixel           Pointer to addition information for each pixel
 *    fltIncR           Increment per iteration for red
 *    fltIncG           Increment per iteration for green
 *    fltIncB           Increment per iteration for blue
 *    u16Step           The step number in the fader
 *    u32InitialRGB     The combine RGB 'initial' colour
 *    u32TransitionRGB  The combine RGB 'transition' colour
 *    u8InitialR        Initial red component
 *    u8InitialG        Initial green component
 *    u8InitialB        Initial blue component
 *    u8TransitionR     Transition red component         
 *    u8TransitionG     Transition green component
 *    u8TransitionB     Transition blue component
 *    u8Steps           Number of steps for the fade transition
 *    uLoop             1=Loop
 *    uRunning          1=Running
 *    uStop             1=Stop
 *  mu16Delay         The delay factor 1 to 32768, 0 = no delay
 *  mu16DelayCtr      The count down delay counter     
 *  mu8NumPixels      Static:Number of pixels to manage             
 *  mu8StepInc        Step size
 *
 * Methods:
 *  clsFader          Constructor
 *  calculate         Works out fader internals
 *  fade              Iterates the fade to the next step in the sequence           
 *  findColor         Gets the colour at the specified step
 *  getInitialRGB     Gets the initial RGB colour
 *  getLoop           Gets the loop flag for the specified pixel
 *  getRunningStatus  Gets the running status flag
 *  getStep           Gets the current step
 *  getSteps          Gets the total number of steps
 *  getTransitionRGB  Gets the transition RGB colour
 *  setCallback       Sets the call-back to call when fade transision completes               
 *  setDelay          Sets the delay factor between fade iterations
 *  setLoopState      Sets the loop state for a pixel fader       
 *  setRunningState   Sets the running state for a pixel fader       
 *  setInitialRGB     Sets the initial RGB colour components
 *  setLoopState      Sets the state of the loop flag
 *  setRunningState   Sets the running flag
 *  setStepIncrement  Sets the step increment size   
 *  setTransitionRGB  Sets the transition RGB colour components
 *  setStep           Sets the step number
 *  setSteps          Sets the number of steps between the from and to colours
 *******************************************************************************
 * History:
 *  2014/11/12 Written by Simon Platten
 */
#ifndef CLSFADER_H
  #define CLSFADER_H

  #include <Arduino.h>
  #include "../Adafruit_NeoPixel/Adafruit_NeoPixel.h"

typedef struct {
  float    fltIncR,           //Increment per iteration for red
           fltIncG,           //Increment per iteration for green
           fltIncB;           //Increment per iteration for blue
  uint16_t u16Step;           //The step number in the fader
  uint32_t u32InitialRGB,     //The combine RGB 'initial' colour
           u32TransitionRGB;  //The combine RGB 'transition' colour
  uint8_t  u8InitialR,        //Initial red component
           u8InitialG,        //Initial green component
           u8InitialB,        //Initial blue component
           u8TransitionR,     //Transition red component         
           u8TransitionG,     //Transition green component
           u8TransitionB,     //Transition blue component
           u8Steps;           //Number of steps for fade transition fade           
//Flags                     
  unsigned uLoop      : 1;    //Loop
  unsigned uRunning   : 1;    //Running fader status
  unsigned uStop      : 1;    //Stop fader from running
} perPixelDef;
 
class clsFader: public Adafruit_NeoPixel {
private:
  void (*mpCallback)(clsFader*, uint8_t);//Function to perform after transition         
  perPixelDef* mpPixel;       //Pointer to addition information for each pixel
  uint8_t   mu8StepInc;       //Step size
  uint16_t  mu16Delay,        //The delay factor 1 to 255, 0 = no delay
            mu16DelayCtr;     //Count down delay counter 
//Works out fader internals
  void  calculate(perPixelDef* pPixel);
  void  calculate(int8_t s8Pixel);
//Gets the colour at the specified step 
  uint32_t findColor(uint8_t u8Pixel);
           
public:
//Function prototypes
//Constructor
  clsFader(uint16_t n, uint8_t p=6, uint8_t t=NEO_GRB + NEO_KHZ800);
//Iterates the fade to the next step in the sequence 
  void     fade(void);
//Gets the initial RGB colour 
  uint32_t getInitialRGB(uint8_t u8Pixel);
//Gets the loop flag for the specified pixel 
  unsigned getLoop(uint8_t u8Pixel);
//Gets the running status flag 
  unsigned getRunningStatus(uint8_t u8Pixel);
//Gets the current step 
  uint16_t getStep(uint8_t u8Pixel);
//Gets the total number of steps 
  uint8_t  getSteps(uint8_t u8Pixel);
//Gets the transition RGB colour 
  uint32_t getTransitionRGB(uint8_t u8Pixel);
//Sets the call-back to call when fade transision completes 
  void     setCallback(void (*pCallback)(clsFader* p, uint8_t u8Pixel));
//Sets the delay factor between fade iterations 
  void     setDelay(uint16_t u16Delay);
//Sets the initial RGB colour components
  void     setInitialRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                           int8_t s8Pixel = -1);
//Sets the intial RGB colour 
  void     setInitialRGB(uint32_t u32RGB, int8_t s8Pixel = -1); 
//Sets the state of the loop flag 
  void     setLoopState(boolean blnState = true, int8_t s8Pixel = -1);
//Sets the running flag   
  void     setRunningState(boolean blnState = true, int8_t s8Pixel = -1);
//Sets the step increment size 
  void     setStepIncrement(uint8_t u8StepInc);
//Sets the final RGB colour components
  void     setTransitionRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                           int8_t s8Pixel = -1);
//Sets the transition RGB colour 
  void     setTransitionRGB(uint32_t u32RG, int8_t s8Pixel = -1); 
//Sets the step number
  void     setStep(uint16_t u16Step, int8_t s8Pixel = -1);
//Sets the number of steps between the from and to colours
  void     setSteps(uint8_t u8Steps, int8_t s8Pixel = -1);
};

#endif // CLSFADER_H           


clsFader.cpp:
Code: Select all | TOGGLE FULL SIZE
/**
 * File:
 *  clsFader.cpp
 * 
 * Notes:
 *  This file contains the implementation of the class 'clsFader'
 *   
 * History:
 *  2014/11/12 Written by Simon Platten
 */
/**
* Default constructor
*/
#include <Math.h>
#include <clsFader.h>

//#define DEBUG_INFO 1
/*******************************************************************************
 * Default constructor
 ******************************************************************************/
clsFader::clsFader(uint16_t n, uint8_t p, uint8_t t)
                                                  : Adafruit_NeoPixel(n, p, t) {
  if ( n > 0 ) {
    mpPixel = new perPixelDef[n];
   
    for( uint8_t p=0; p<n; p++ ) {
      memset(&mpPixel[p], 0, sizeof(perPixelDef));
    }
  }
  setStepIncrement(1);
  setCallback(NULL);
  setSteps(255);
  setDelay(0);
}
/**
 * calculate
 * Parameters:
 *  pPixel, the pixel definition   
 * Works out fader internal for the passed pixel
 */ 
void clsFader::calculate(perPixelDef* pPixel) {
//Combine the 'initial' components 
  pPixel->u32InitialRGB = (((uint32_t)pPixel->u8InitialR) << 0x10) |
                          (((uint32_t)pPixel->u8InitialG) << 0x08) |
                           ((uint32_t)pPixel->u8InitialB);
//Combine the 'transition' components 
  pPixel->u32TransitionRGB = (((uint32_t)pPixel->u8TransitionR) << 0x10) |
                             (((uint32_t)pPixel->u8TransitionG) << 0x08) |
                              ((uint32_t)pPixel->u8TransitionB);
// Work out the transition colours for the steps between min and max
  uint8_t u8DiffR = abs(pPixel->u8InitialR - pPixel->u8TransitionR),
          u8DiffG = abs(pPixel->u8InitialG - pPixel->u8TransitionG),
          u8DiffB = abs(pPixel->u8InitialB - pPixel->u8TransitionB);
  pPixel->fltIncR = (float)u8DiffR / (float)pPixel->u8Steps;
  pPixel->fltIncG = (float)u8DiffG / (float)pPixel->u8Steps;
  pPixel->fltIncB = (float)u8DiffB / (float)pPixel->u8Steps;
//Reset the step number for each pixel                       
  pPixel->u16Step = 0; 
}
/**
 * calculate
 * Parameters:
 *  u8Pixel, the pixel number base 0 
 * Works out fader internals
 */ 
void clsFader::calculate(int8_t s8Pixel) {
  perPixelDef* pPixel;
 
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      calculate(&mpPixel[u8Pixel]);
    }
  } else if ( s8Pixel < numPixels() ) {
    calculate(&mpPixel[s8Pixel]);
  }
}
/**
 * fade
 * Services the fader, must be started first
 */   
void clsFader::fade(void) {
  if ( mu16DelayCtr > 0 ) {
//Delay between fade iterations, not 0 yet, return 
    mu16DelayCtr--;
    return;
  } else {
    mu16DelayCtr = mu16Delay;
  }
  for( uint8_t f=0; f<numPixels(); f++ ) {
    perPixelDef* pPixel = &mpPixel[f];
   
    if ( !pPixel->uRunning ) {
      continue;
    }
    uint32_t u32Color = findColor(f);
    setPixelColor(f, u32Color);   
#ifdef DEBUG_INFO   
    if ( f == 0 ) {
      Serial.print("pixel[");
      Serial.print(f);
      Serial.print("] initialRGB[");
      Serial.print(pPixel->u32InitialRGB, HEX);
      Serial.print("] transitionRGB[");
      Serial.print(pPixel->u32TransitionRGB, HEX);
      Serial.print("] step[");
      Serial.print(pPixel->u16Step);
      Serial.print("] steps[");
      Serial.print(pPixel->u8Steps);
      Serial.print("] inc[");
      Serial.print(mu8StepInc);
      Serial.print("] color[");
      Serial.print(u32Color, HEX);
      Serial.print("] loop[");
      Serial.print(pPixel->uLoop);
      Serial.print("]\n");
    }
#endif   
    if ( pPixel->u16Step == pPixel->u8Steps ) {
      if ( mpCallback != NULL ) {
//Perform callback now
        (*mpCallback)(this, f);
//Work out the internals
        calculate(f);           
      } else {
        if ( pPixel->uLoop ) {
          pPixel->u16Step = 0;
        } else {
          pPixel->uStop = true;
        }
      }
    }
    if ( pPixel->uStop ) {
      pPixel->uRunning = false;
      continue;
    }
    pPixel->u16Step = min(pPixel->u8Steps, pPixel->u16Step + mu8StepInc);       
  }
  show();
}
/**
 * findColor
 * Parameters:
 *  u8Pixel, the index of the pixel 0 to n
 * Returns:
 *  The colour at the specfied step
 */       
uint32_t clsFader::findColor(uint8_t u8Pixel) {
  perPixelDef* pPixel = &mpPixel[u8Pixel];
 
  if ( pPixel->u16Step > pPixel->u8Steps ) {
    pPixel->u16Step = pPixel->u8Steps;
  }   
  uint8_t u8R = (uint8_t)((float)pPixel->u16Step * pPixel->fltIncR) & 0xff,
          u8G = (uint8_t)((float)pPixel->u16Step * pPixel->fltIncG) & 0xff,
          u8B = (uint8_t)((float)pPixel->u16Step * pPixel->fltIncB) & 0xff;
  uint32_t u32RGB = pPixel->u32InitialRGB ^ (((uint32_t)u8R << 0x10) |
                                             ((uint32_t)u8G << 0x08) |
                                             ((uint32_t)u8B));
  return u32RGB;
}
/**
 * getInitialRGB
 * Parameters:
 *  u8Pixel, the index of the pixel 0 to n
 * Returns: The initial RGB colour
 */ 
uint32_t clsFader::getInitialRGB(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u32InitialRGB;
  }
  return 0;
}
/**
 * getLoop
 * Parameters:
 *  u8Pixel, the pixel to check 
 * Returns: the state of the loop flag for the specified pixel
 */ 
unsigned clsFader::getLoop(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].uLoop;
  }
  return 0;
}
/**
 * getRunningStatus
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: the running status flag
 */   
unsigned clsFader::getRunningStatus(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].uRunning;
  }
  return 0;
}
/**
 * getStep
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: the current step
 */ 
uint16_t clsFader::getStep(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u16Step;
  }
  return 0;
}
/**
 * getSteps
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: the total number of steps
 */ 
uint8_t clsFader::getSteps(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u8Steps;
  }
  return 0;
}
/**
 * getTransitionRGB
 * Parameters:
 *  u8Pixel, the pixel to query 
 * Returns: The transition RGB colour
 */   
uint32_t clsFader::getTransitionRGB(uint8_t u8Pixel) {
  if ( u8Pixel < numPixels() ) {
    return mpPixel[u8Pixel].u32TransitionRGB;
  }
  return 0;
}
/**
 * setCallback
 * Parameters:
 *  pCallback, pointer to function to call when transition completes
 */   
void clsFader::setCallback(void (*pCallback)(clsFader* p, uint8_t u8Pixel)) {
  mpCallback = pCallback;
}
/**
 * setDelay
 * Parameters:
 *  u8Delay, the delay to set between fade iterations 1 to 255, 0 = no delay
 */   
void clsFader::setDelay(uint16_t u16Delay) {
  mu16Delay = mu16DelayCtr = u16Delay;
}
/**
 * setInitialRGB
 * Parameters:
 *  u8Red, the red component 0 to 255
 *  u8Green, the green component 0 to 255
 *  u8Blue, the blue component 0 to 255
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setInitialRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                               int8_t s8Pixel) {
  perPixelDef* pPixel;
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      pPixel = &mpPixel[u8Pixel];
      pPixel->u8InitialR = u8Red;
      pPixel->u8InitialG = u8Green;
      pPixel->u8InitialB = u8Blue;
    }
  } else if ( s8Pixel < numPixels() ) { 
      pPixel = &mpPixel[s8Pixel];
      pPixel->u8InitialR = u8Red;
      pPixel->u8InitialG = u8Green;
      pPixel->u8InitialB = u8Blue;
  }
}
/**
 * setInitialRGB
 * Parameters:
 *  u32RGB, the Red, Green and Blue 32bit colour value
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setInitialRGB(uint32_t u32RGB, int8_t s8Pixel) {
  setInitialRGB(((u32RGB >> 0x10) & 0xff),
                ((u32RGB >> 0x08) & 0xff),
                (u32RGB & 0xff), s8Pixel);

/**
 * setLoopState
 * Parameters:
 *  blnState, optional, true=fadeout, false=fadein 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 */ 
void clsFader::setLoopState(boolean blnState, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      mpPixel[u8Pixel].uLoop = (blnState == true) ? 1 : 0;
    }
  } else if ( s8Pixel < numPixels() ) { 
    mpPixel[s8Pixel].uLoop = (blnState == true) ? 1 : 0;
  }
}
/**
 * setRunningState
 * Parameters:
 *  blnState, optional, true=fadeout, false=fadein 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 */   
void clsFader::setRunningState(boolean blnState, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      mpPixel[u8Pixel].uRunning = (blnState == true) ? 1 : 0;
    }
  } else if ( s8Pixel < numPixels() ) { 
    mpPixel[s8Pixel].uRunning = (blnState == true) ? 1 : 0;
  }
  if ( blnState == true ) {
//Work out the internals
    calculate(-1);
  }           
}
/**
 * setTransitionRGB
 * Parameters:
 *  u8Red, the red component 0 to 255
 *  u8Green, the green component 0 to 255
 *  u8Blue, the blue component 0 to 255
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setTransitionRGB(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue,
                                                               int8_t s8Pixel) {
  perPixelDef* pPixel;
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      pPixel = &mpPixel[u8Pixel];
      pPixel->u8TransitionR = u8Red;
      pPixel->u8TransitionG = u8Green;
      pPixel->u8TransitionB = u8Blue;
    }
  } else if ( s8Pixel < numPixels() ) { 
      pPixel = &mpPixel[s8Pixel];
      pPixel->u8TransitionR = u8Red;
      pPixel->u8TransitionG = u8Green;
      pPixel->u8TransitionB = u8Blue;
  }
}
/**
 * setTransitionRGB
 * Parameters:
 *  u32RGB, the Red, Green and Blue 32bit colour value
 *  s8Pixel, optional pixel to modify
 */     
void clsFader::setTransitionRGB(uint32_t u32RGB, int8_t s8Pixel) {
  setTransitionRGB(((u32RGB >> 0x10) & 0xff),
                   ((u32RGB >> 0x08) & 0xff),
                    (u32RGB & 0xff), s8Pixel);

/**
 * setStepIncrement
 * Parameters:
 *  u8StepInc, the step increment size, min 1 
 */ 
void clsFader::setStepIncrement(uint8_t u8StepInc) {
  if ( u8StepInc > 0 ) {
    mu8StepInc = u8StepInc;
  }
}
/**
 * setStep
 * Paramters:
 *  u16Step, the step number to use 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 * Sets the step number
 */ 
void clsFader::setStep(uint16_t u16Step, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      if ( u16Step >= mpPixel[u8Pixel].u8Steps ) {
        u16Step =0;
      }
      mpPixel[u8Pixel].u16Step = u16Step;
    }
  } else if ( s8Pixel < numPixels() ) {
    mpPixel[s8Pixel].u16Step = u16Step; 
  }
}
/**
 * setSteps
 * Paramters:
 *  u8Steps, the number of steps to use 
 *  s8Pixel, optional, default=-1 (all) or index of pixel base 0 to effect
 * Sets the number of steps between the transitions 0 to 255
 */ 
void clsFader::setSteps(uint8_t u8Steps, int8_t s8Pixel) {
  if ( s8Pixel < 0 ) {
    for( uint8_t u8Pixel=0; u8Pixel<numPixels(); u8Pixel++ ) {
      mpPixel[u8Pixel].u8Steps = max(1, u8Steps);
    }
  } else if ( s8Pixel < numPixels() ) { 
    mpPixel[s8Pixel].u8Steps = max(1, u8Steps);
  }
}


Any suggestions please let me know.

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel faders

by splatten on Sun Nov 23, 2014 9:27 am


splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel faders

by splatten on Sat Nov 29, 2014 1:45 pm

Improved class and posted another video.

https://www.youtube.com/watch?v=Qv2LU5MNOLo

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel faders

by splatten on Sun Nov 30, 2014 8:14 am

Modified the library again, now the funcitons accept a 32bit pixel mask, which allow for patterns of LED's to be specified, new video uploaded showing simple pattern.

https://www.youtube.com/watch?v=gYMM4_0 ... e=youtu.be

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel faders

by splatten on Sat Dec 06, 2014 9:04 am

Added 2nd neopixel ring to the demo, one 24 pixel ring, the other 16 pixel ring, I found that the LED's seem to be ordered differently, with the 24 pixel ring wire 0 to 23 clockwise and the 16 pixel ring 0 to 15 wired anti-clockwise.

https://www.youtube.com/watch?v=ZgEV1gz ... e=youtu.be

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel faders

by chemdoc77 on Sat Dec 06, 2014 11:51 am

Hi Simon:

Awesome. Fantastic work!

Thank you for sharing your code, too!

I can’t wait to try it out on my NeoPixel rings!

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 143
Joined: Mon Jan 28, 2013 9:32 am

Re: NeoPixel faders

by splatten on Sat Dec 06, 2014 11:54 am

Hope you like it, any suggestions please let me know.

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel class for faders and transistions

by jayt95 on Fri Jun 01, 2018 3:35 pm

Is the code in the latest video still available? It's been really useful for my project!

jayt95
 
Posts: 9
Joined: Tue Aug 09, 2016 12:46 pm

Re: NeoPixel class for faders and transistions

by splatten on Sun Jun 03, 2018 2:37 am

I haven't taken anything down so it should still be on YouTube. For the source code, see the post above.

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel class for faders and transistions

by jayt95 on Mon Jun 04, 2018 9:34 am

Looks like the link isn't working on the first Youtube link above, but I do see the code here in the forum for the first few iterations. I'm really interested in the 2 ring setup (which happens to use the exact same LED rings I'm using). I'm trying to adapt the code above to use two rings, but it's a bit more complex than I'm used to!

jayt95
 
Posts: 9
Joined: Tue Aug 09, 2016 12:46 pm

Re: NeoPixel class for faders and transistions

by splatten on Mon Jun 04, 2018 9:39 am

I'll see what I have on my memory sticks tonight...away from home for a few days.

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel class for faders and transistions

by jayt95 on Mon Jun 04, 2018 9:43 am

That would be perfect, thanks so much!

jayt95
 
Posts: 9
Joined: Tue Aug 09, 2016 12:46 pm

Re: NeoPixel class for faders and transistions

by splatten on Mon Jun 04, 2018 2:32 pm

The site where I use to upload files to is now gone, I've attached the files here.
Attachments
ringdemo.zip
(10.09 KiB) Downloaded 23 times

splatten
 
Posts: 426
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Re: NeoPixel class for faders and transistions

by jayt95 on Mon Jun 04, 2018 5:52 pm

Works perfectly, thanks again for posting!

jayt95
 
Posts: 9
Joined: Tue Aug 09, 2016 12:46 pm

Please be positive and constructive with your questions and comments.