SK6812 understanding

Hi All,

Just recently purchased my first RGBW led strip. I have been tinkering with the adafruit neopixel library and can get the test to work just fine. My hiccup is I have no idea what any of the lines of code are really doing. I see the brief notes as to what is happening but it's not clicking in my head yet. Is there a tutorial on this that I can play around with that has a list of all of the "commands" Ultimately my goal is to have a pushbutton/encoder change the color and speed of a chasing effect. I'm sure it's right under my nose the answer i am looking for, but either i'm not really sure what it's called or i'm a "big dummy". an arrow in the right direction would be great.

Thank you for your time.
:o

This Adafruit tutorial may be of interest.

Don't know how i missed this..! will start reading thank you.

groundFungus:
This Adafruit tutorial may be of interest.

Thank you so much for this. I was looking for the wrong terminology all along.

I’ve managed to change some code around mixing and matching from various other codes and experimenting with variables and what nots. The code is near finished for what I would like to do. However I could use some assistance with changing an int to a variable number that is defined by a pot.

I would like to make the speed adjustable. the problem lies that i have included the speed in each of the routines.

Another item i will eventually incorporate is a brightness pot.

lastly I would like to separate the 2 types of sequences by using a switch. but that is a luxury not a necessity.

here is my code.

#include <Adafruit_NeoPixel.h>
#include <EEPROM.h>
#define BRIGHTNESS 60
#define NUM_LEDS 21 
#define PIN 6 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);

#define BUTTON 2
byte selectedEffect=0;

void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
  strip.setBrightness(BRIGHTNESS);
}

// *** REPLACE FROM HERE ***
void loop() { 
  EEPROM.get(0,selectedEffect); 
  
  if(selectedEffect>8) { 
    selectedEffect=0;
    EEPROM.put(0,0); 
  } 
  
  switch(selectedEffect) {
    
    case 1  : {
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(255, 0, 0, 0, 1, 50, 0);
                break;
              }

    case 2  : {
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(0, 255, 0, 0, 1, 50, 0);
                break;
              }
              
    case 3  : {
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(0, 0, 255, 0, 1, 50, 0);
                break;
              }

    case 4  : {
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(0, 0, 0, 255, 1, 50, 0);
                break;
              }
    
    case 5  : {
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(255, 0, 0, 0, 1, 50, 0);
                break;
              }
    case 6  : {
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(0, 255, 0, 0, 1, 50, 0);
                break;
              }
    case 7  : {
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(0, 0, 255, 0, 1, 50, 0);
                break;
              }
    case 8  : {
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(0, 0, 0, 255, 1, 50, 0);
                break;
              }
  }
}

void changeEffect() {
  if (digitalRead (BUTTON) == HIGH) {
    selectedEffect++;
    EEPROM.put(0, selectedEffect);
    asm volatile ("  jmp 0");
  }
}


// *************************
// ** LEDEffect Functions **
// *************************
void CylonBounce(byte red, byte green, byte blue, byte white, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize; i++) {
    setAll(0,0,0,0);
    setPixel(i, red/10, green/10, blue/10, white/10);
    for(int j = 1; j == EyeSize; j++) {
    setPixel(i, red, green, blue, white); 
    }
        showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize; i > 0; i--) {
    setAll(0,0,0,0);
    for(int j = 1; j == EyeSize; j++) {
     setPixel(i, red, green, blue, white); 
    }
    showStrip();
    delay(SpeedDelay);
  }
  
  delay(ReturnDelay);
}

void NewKITT(byte red, byte green, byte blue, byte white, int EyeSize, int SpeedDelay, int ReturnDelay){
  OutsideToCenter(red, green, blue, white, EyeSize, SpeedDelay, ReturnDelay);
}
// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, byte white, int EyeSize, int SpeedDelay, int ReturnDelay) 
   { 
    for(int i = 0; i <= NUM_LEDS; i++) {
    setAll(0,0,0,0);
    for(int j = 0; j <= 0; j++) {
    setPixel(i+j-1, red, green, blue, white); 
    }
    for(int j = 1; j <= EyeSize+1; j++) {
    setPixel(NUM_LEDS-i, red, green, blue, white); 
    }
    
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    }


// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.show();
 #endif
 
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue, byte white) {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue, white));
 #endif
  
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue, byte white) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue, white); 
  }
  showStrip();
}

You would read the speed pot with analogRead(). The analogRead() function returns an int between 0 and 1023. To change that number to a range of speed values, use the map() function. If the range of values for speed are, say, 10 to 500 use:

int speed = map(potValue, 0, 1023, 10, 500);

Then, in the calls to the effect functions, use the speed variable in the parameter list.

CylonBounce(255, 0, 0, 0, 1, speed, 0);

learned some more about analogRead. pretty much cut and dry. It seems to work but has incredibly slow response time. I understand it will need to make one complete pass through the code before it updates but i put in the print serial command and it’s taking 2 trips through the code before it updates. it is put someplace wrong? The code is posted 2 times so i can show the bold where i’ve made changes.

#include <Adafruit_NeoPixel.h>
#include <EEPROM.h>
#define BRIGHTNESS 5
#define NUM_LEDS 21 
#define PIN 6 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
#define BUTTON 2
byte selectedEffect=0;
int analogPin = 3;
int val;
int fast;


void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
  strip.setBrightness(BRIGHTNESS);
  Serial.begin(9600);
  
}

// *** REPLACE FROM HERE ***
void loop() { 
  EEPROM.get(0,selectedEffect); 
    if(selectedEffect>8) { 
    selectedEffect=0;
    EEPROM.put(0,0); 
    
  } 
  
  switch(selectedEffect) {
    
    case 1  : { int fast = map(val, 0, 1023, 0, 100);
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(255, 0, 0, 0, 1, fast, 0);
                
                break;
              }

    case 2  : { int fast = map(val, 0, 1023, 0, 100);
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(0, 255, 0, 0, 1, fast, 0);
                break;
              }
              
    case 3  : { int fast = map(val, 0, 1023, 0, 100);
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(0, 0, 255, 0, 1, fast, 0);
                break;
              }

    case 4  : { int fast = map(val, 0, 1023, 0, 100);
                // CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
                CylonBounce(0, 0, 0, 255, 1, fast, 0);
                break;
              }
    
    case 5  : { 
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(255, 0, 0, 0, 1, 50, 0);
                break;
              }
    case 6  : {
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(0, 255, 0, 0, 1, 50, 0);
                break;
              }
    case 7  : {
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(0, 0, 255, 0, 1, 50, 0);
                break;
              }
    case 8  : {
                // NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
                NewKITT(0, 0, 0, 255, 1, 50, 0);
                break;
              }
  }
}

void changeEffect() {
  if (digitalRead (BUTTON) == HIGH) {
    selectedEffect++;
    EEPROM.put(0, selectedEffect);
    asm volatile ("  jmp 0");
  }
}


// *************************
// ** LEDEffect Functions **
// *************************
void CylonBounce(byte red, byte green, byte blue, byte white, int EyeSize, int fast, int ReturnDelay){

  val = analogRead(analogPin);
    Serial.println(fast);
  
  for(int i = 0; i < NUM_LEDS-EyeSize; i++) {
    setAll(0,0,0,0);
    setPixel(i, red/10, green/10, blue/10, white/10);
    for(int j = 1; j == EyeSize; j++) {
    setPixel(i, red, green, blue, white); 
    }
        showStrip();
    delay(fast);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize; i > 0; i--) {
    setAll(0,0,0,0);
    for(int j = 1; j == EyeSize; j++) {
     setPixel(i, red, green, blue, white); 
    }
    showStrip();
    delay(fast);
  }
  
  delay(ReturnDelay);
}

void NewKITT(byte red, byte green, byte blue, byte white, int EyeSize, int SpeedDelay, int ReturnDelay){
  OutsideToCenter(red, green, blue, white, EyeSize, SpeedDelay, ReturnDelay);
}
// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, byte white, int EyeSize, int SpeedDelay, int ReturnDelay) 
   { 
    for(int i = 0; i <= NUM_LEDS; i++) {
    setAll(0,0,0,0);
    for(int j = 0; j <= 0; j++) {
    setPixel(i+j-1, red, green, blue, white); 
    }
    for(int j = 1; j <= EyeSize+1; j++) {
    setPixel(NUM_LEDS-i, red, green, blue, white); 
    }
    
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    }


// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.show();
 #endif
 
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue, byte white) {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue, white));
 #endif
  
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue, byte white) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue, white); 
  }
  showStrip();
}

My changes are in bold

Also to note that when i change it resets to zero and has to be updated. creating a strobe like effect to start with.

#include <Adafruit_NeoPixel.h>
#include <EEPROM.h>
#define BRIGHTNESS 5
#define NUM_LEDS 21
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
#define BUTTON 2
byte selectedEffect=0;
int analogPin = 3;
int val;
int fast;

void setup()
{
strip.begin();
strip.show(); // Initialize all pixels to ‘off’
digitalWrite (BUTTON, HIGH); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
strip.setBrightness(BRIGHTNESS);
Serial.begin(9600);

}

// *** REPLACE FROM HERE ***
void loop() {
EEPROM.get(0,selectedEffect);
if(selectedEffect>8) {
selectedEffect=0;
EEPROM.put(0,0);

}

switch(selectedEffect) {

case 1 : { int fast = map(val, 0, 1023, 0, 100);
// CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
CylonBounce(255, 0, 0, 0, 1, fast, 0);

break;
}

case 2 : { int fast = map(val, 0, 1023, 0, 100);
// CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
CylonBounce(0, 255, 0, 0, 1, fast, 0);
break;
}

case 3 : { int fast = map(val, 0, 1023, 0, 100);
// CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
CylonBounce(0, 0, 255, 0, 1, fast, 0);
break;
}

case 4 : { int fast = map(val, 0, 1023, 0, 100);
// CylonBounce - Color (red, green, blue, white), eye size, speed delay, end pause
CylonBounce(0, 0, 0, 255, 1, fast, 0);
break;
}

case 5 : {
// NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
NewKITT(255, 0, 0, 0, 1, 50, 0);
break;
}
case 6 : {
// NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
NewKITT(0, 255, 0, 0, 1, 50, 0);
break;
}
case 7 : {
// NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
NewKITT(0, 0, 255, 0, 1, 50, 0);
break;
}
case 8 : {
// NewKITT - Color (red, green, blue, white), eye size, speed delay, end pause
NewKITT(0, 0, 0, 255, 1, 50, 0);
break;
}
}
}

void changeEffect() {
if (digitalRead (BUTTON) == HIGH) {
selectedEffect++;
EEPROM.put(0, selectedEffect);
asm volatile (" jmp 0");
}
}

// *************************
// ** LEDEffect Functions **
// *************************
void CylonBounce(byte red, byte green, byte blue, byte white, int EyeSize, int fast, int ReturnDelay){

val = analogRead(analogPin);
** Serial.println(fast);**

for(int i = 0; i < NUM_LEDS-EyeSize; i++) {
setAll(0,0,0,0);
setPixel(i, red/10, green/10, blue/10, white/10);
for(int j = 1; j == EyeSize; j++) {
setPixel(i, red, green, blue, white);
}
showStrip();
delay(fast);
}

delay(ReturnDelay);

for(int i = NUM_LEDS-EyeSize; i > 0; i–) {
setAll(0,0,0,0);
for(int j = 1; j == EyeSize; j++) {
setPixel(i, red, green, blue, white);
}
showStrip();
delay(fast);
}

delay(ReturnDelay);
}

void NewKITT(byte red, byte green, byte blue, byte white, int EyeSize, int SpeedDelay, int ReturnDelay){
OutsideToCenter(red, green, blue, white, EyeSize, SpeedDelay, ReturnDelay);
}
// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, byte white, int EyeSize, int SpeedDelay, int ReturnDelay)
{
for(int i = 0; i <= NUM_LEDS; i++) {
setAll(0,0,0,0);
for(int j = 0; j <= 0; j++) {
setPixel(i+j-1, red, green, blue, white);
}
for(int j = 1; j <= EyeSize+1; j++) {
setPixel(NUM_LEDS-i, red, green, blue, white);
}

showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}

// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif

}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue, byte white) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue, white));
#endif

}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue, byte white) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue, white);
}
showStrip();
}