0

Furscarf Code Editing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Furscarf Code Editing

by jeremyzschau on Thu Oct 05, 2017 5:39 pm

Can I edit fur scarf code so I can input specific RGB colors like in my Yukata code?

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
 
#define PIN 1

int mode = 5; //keep track of which mode we're running in
long menuTime;
// Pushbutton setup
int buttonPin = 0;             // the number of the pushbutton pin
int buttonState;               // the current reading from the input pin
int lastButtonState = HIGH;    // the previous reading from the input pin
long buttonHoldTime = 0;         // the last time the output pin was toggled
long buttonHoldDelay = 1000;      // how long to hold the button down
int numberofmodes = 5;


Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_RGB + NEO_KHZ800);

//colors for each mode to be accessed by button presses
//mode 1                  R   G   B
uint8_t mode1Colors[][11] = {
                          {180, 0, 160},
                          {255, 51, 255},
                          {83, 54, 164},
                          {153, 51, 255},
                          {204, 51, 255},
                          {153, 0, 204},
                          {50, 80, 145},
                          {255, 51, 204},
                          {204, 0, 51},
                          {70, 0, 255},
                          {204, 102, 255},
                          };
//mode2
uint8_t mode2Colors[][5] = {
                         {248, 255, 231},
                         {60, 60, 150},
                         {62, 75, 153},
                         {87, 57, 167},
                         {90, 116, 166},
                          };
//mode3
uint8_t mode3Colors[][10] = {
                         {114, 193, 175},
                         {193, 238, 219},
                         {186, 252, 127},
                         {95, 240, 146},
                         {69, 236, 150},
                         {255, 255, 255},
                         {44, 105, 145},
                         {8, 233, 136},
                         {91, 163, 164},
                         {191, 217, 220},                         
                          };

//sizes of each array
#define M1COLORS 11
#define M2COLORS 5
#define M3COLORS 10



void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  if ( mode == 5 ) {  //"sleep" mode
    sleep(50);
  }
  else if ( mode == 4 ) {
    rainbowCycle(20);
  }
  else {
    flashRandom(50, 8);  // first number is 'wait' delay, shorter num == shorter twinkle
  }
 
}

void sleep(uint8_t wait) {
    colorWipe(strip.Color(0, 0, 0), 100);

      //Check for button presses to change mode
      //check for button presses each loop
      int buttonState = digitalRead(buttonPin);
      if (buttonState == LOW) {
        buttonCheck();
      }
      lastButtonState = buttonState;

    strip.show();
    delay(wait);

}

void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
 
  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
      //Check for button presses to change mode
      //check for button presses each loop
      int buttonState = digitalRead(buttonPin);
      if (buttonState == LOW) {
        buttonCheck();
      }
      lastButtonState = buttonState;
      if (mode != 4) {
        break;
      }   
    }
    if (mode != 4) {
    break;
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
 
}

// wipe animation to indicate mode changes
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
  delay(wait);

}



//main function to blink random pixels on and off
void flashRandom(int wait, uint8_t howmany) {
  for(uint16_t i=0; i<howmany; i++) {
    //Check for button presses to change mode
    //check for button presses each loop
    int buttonState = digitalRead(buttonPin);
    if (buttonState == LOW) {
      buttonCheck();
    }
    lastButtonState = buttonState;   
    if (mode == 4) { //switch immediately to rainbow if in this mode
      break;
    }     


    int red = 255;
    int green = 0;
    int blue = 0;
    int c = 0;   

    if ( mode == 1 ) {
      c = random(M1COLORS);
      red = mode1Colors[c][0];
      green = mode1Colors[c][1];
      blue = mode1Colors[c][2];         
    }
    else if ( mode == 2 ) {   
      int c = random(M2COLORS);
      red = mode2Colors[c][0];
      green = mode2Colors[c][1];
      blue = mode2Colors[c][2];         
    }
    else if ( mode == 3 ) {   
      int c = random(M3COLORS);
      red = mode3Colors[c][0];
      green = mode3Colors[c][1];
      blue = mode3Colors[c][2];         
    }   
   
    int j = random(strip.numPixels());
    if ( strip.getPixelColor(j) != 0 ) {//if we just selected a pixel with color
      red =  ((byte)(strip.getPixelColor(j)>> 16));
      green = ((byte)(strip.getPixelColor(j)>> 8));
      blue = ((byte)strip.getPixelColor(j));
      strip.setPixelColor(j, strip.getPixelColor(j));

    // & fade out in 5 steps
      for (int x=20; x >= 0; x--) {
        int r = red * x; r /= 20;
        int g = green * x; g /= 20;
        int b = blue * x; b /= 20;
       
        strip.setPixelColor(j, strip.Color(r, g, b));
        strip.show();
        delay(wait);
      } 
    }

    else {
 
      // if pixel already dark,  will 'fade' it in 20 steps
      for (int x=0; x < 20; x++) {
        int r = red * (x+1); r /= 20;
        int g = green * (x+1); g /= 20;
        int b = blue * (x+1); b /= 20;
       
        strip.setPixelColor(j, strip.Color(r, g, b));
        strip.show();
        delay(wait);
      }
    }
  }
  // LEDs will be off when done (they are faded to 0)
}

void buttonCheck() {
  menuTime = millis();
  int buttonState = digitalRead(buttonPin);
  if (buttonState == LOW && lastButtonState == HIGH ) {
    buttonHoldTime = millis();
  }
 
  if (buttonState == LOW && lastButtonState == LOW ) {
//    Serial.println( "Button Press");
    if ((millis() - buttonHoldTime) > buttonHoldDelay) {
     
      if(mode == numberofmodes) {
        mode = 1;
//        lastMin = 16;
//        lastHour = 16;
//        colorWipe(strip.Color(0, 0, 0), 100);
        colorWipe(strip.Color(255, 255, 255), 20);
        colorWipe(strip.Color(0, 0, 0), 100);

      }
      else {
        mode += 1;

        colorWipe(strip.Color(255, 255, 255), 20);
        colorWipe(strip.Color(0, 0, 0), 100);
      }
      //add mode indicators here?
      buttonHoldTime = millis();
//      buttonLastPress = millis();

    }
  }
}


Code: Select all | TOGGLE FULL SIZE
#include <FastLED.h>
 
#define LED_PIN      1   // which pin your pixels are connected to
#define NUM_LEDS     4   // how many LEDs you have
#define BRIGHTNESS 180   // 0-255, higher number is brighter.
#define SATURATION 255   // 0-255, 0 is pure white, 255 is fully saturated color
#define SPEED        5   // How fast the colors move.  Higher numbers = faster motion
#define STEPS        5   // How wide the bands of color are.  1 = more like a gradient, 10 = more like stripes
#define BUTTON_PIN   2   // button is connected to pin 2 and GND
 
#define COLOR_ORDER GRB  // Try mixing up the letters (RGB, GBR, BRG, etc) for a whole new world of color combinations
 
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette( PartyColors_p );
TBlendType    currentBlending;
int ledMode = 0;
 
 
//FastLED comes with several palettes pre-programmed.  I like purple a LOT, and so I added a custom purple palette.
 
const TProgmemPalette16 PurpleColors_p PROGMEM =
{
  CRGB::Purple,
  CRGB::Purple,
  CRGB::MidnightBlue,
  CRGB::MidnightBlue,
 
  CRGB::Purple,
  CRGB::Purple,
  CRGB::BlueViolet,
  CRGB::BlueViolet,
 
  CRGB::DarkTurquoise,
  CRGB::DarkTurquoise,
  CRGB::DarkBlue,
  CRGB::DarkBlue,
 
  CRGB::Purple,
  CRGB::Purple,
  CRGB::BlueViolet,
  CRGB::BlueViolet
};
 
 
unsigned long keyPrevMillis = 0;
const unsigned long keySampleIntervalMs = 25;
byte longKeyPressCountMax = 80;    // 80 * 25 = 2000 ms
byte longKeyPressCount = 0;
 
byte prevKeyState = HIGH;         // button is active low
 
void setup() {
  delay( 2000 ); // power-up safety delay
  FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(  BRIGHTNESS );
  currentBlending = BLEND;
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}
 
void loop() {
 
  byte currKeyState = digitalRead(BUTTON_PIN);
 
  if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
    shortKeyPress();
  }
  prevKeyState = currKeyState;
 
  static uint8_t startIndex = 0;
  startIndex = startIndex + 1; /* motion speed */
 
  switch (ledMode) {
 
  case 0:
    currentPalette = HeatColors_p;    //Red & Yellow, Fire Colors
    break;
  case 1:
    currentPalette = ForestColors_p;    //Foresty greens and yellows
    break;
  case 2:
    currentPalette = OceanColors_p;  //Oceans are pretty and filled with mermaids
    break;
  case 3:
    currentPalette = PurpleColors_p;  //My custom palette from above
    break;
  case 4:
    currentPalette = RainbowColors_p;  //All the colors!
    break;
  case 5:
    currentPalette = RainbowStripeColors_p;   //Rainbow stripes
    break;     
  case 6:
    currentPalette = PartyColors_p; //All the colors except the greens, which make people look a bit washed out
    break;
  }
 
  FillLEDsFromPaletteColors( startIndex);
  FastLED.show();
  FastLED.delay(1000 / SPEED); 
}
 
void FillLEDsFromPaletteColors( uint8_t colorIndex) {
 for( int i =  NUM_LEDS; i >= 0; i--) {
   leds[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);
   colorIndex += STEPS;             
 }
}
 
void shortKeyPress() {
  ledMode++;
  if (ledMode > 6) {
    ledMode=0;
  } 
}

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by adafruit_support_carter on Tue Oct 10, 2017 11:08 am

Should be able to do this. The Fur Scarf code uses the Fast LED library, so just look there for what you're after:
https://github.com/FastLED/FastLED

adafruit_support_carter
 
Posts: 3134
Joined: Tue Nov 29, 2016 2:45 pm

Re: Furscarf Code Editing

by jeremyzschau on Wed Oct 11, 2017 5:02 pm

Sorry I am not sure what to look for in the library.

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by adafruit_support_carter on Wed Oct 11, 2017 5:10 pm

Looks like they keep their main doc in a wiki:
https://github.com/FastLED/FastLED/wiki/Overview
and here's the basic color setting methods:
https://github.com/FastLED/FastLED/wiki ... lling-leds

adafruit_support_carter
 
Posts: 3134
Joined: Tue Nov 29, 2016 2:45 pm

Re: Furscarf Code Editing

by jeremyzschau on Wed Oct 11, 2017 6:36 pm

I did read the links but I am sorry I still don't understand how to edit the fur scarf colors.

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by adafruit_support_carter on Wed Oct 11, 2017 7:13 pm

These lines of code in the loop() are calling the FastLED functions:
Code: Select all | TOGGLE FULL SIZE
  FillLEDsFromPaletteColors( startIndex);
  FastLED.show();
  FastLED.delay(1000 / SPEED);

but the main work is being done in the FillLEDsFromPaletteColors() function:
Code: Select all | TOGGLE FULL SIZE
void FillLEDsFromPaletteColors( uint8_t colorIndex) {
 for( int i =  NUM_LEDS; i >= 0; i--) {
   leds[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);
   colorIndex += STEPS;             
 }
}

specifically, this line:
Code: Select all | TOGGLE FULL SIZE
   leds[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);

You could either try and interject your colors there, or redo the whole setup up to try and drive the LEDs in a different way.

Another approach might be to try and create your own palette like the PurpleColors_p one that is created near the top of the sketch.

adafruit_support_carter
 
Posts: 3134
Joined: Tue Nov 29, 2016 2:45 pm

Re: Furscarf Code Editing

by jeremyzschau on Thu Oct 12, 2017 5:37 pm

Thank you so much. Can you please show an example of what the code looks if it can be edited with RGB colors. I am looking for code that shows 255, 255, 255 or three numbers which represent a color. For example I don't understand what the code is for CRGB::Purple. Who decided what Purple or MidnightBlue are?
Code: Select all | TOGGLE FULL SIZE
#define COLOR_ORDER GRB  // Try mixing up the letters (RGB, GBR, BRG, etc) for a whole new world of color combinations
 
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette( PartyColors_p );
TBlendType    currentBlending;
int ledMode = 0;
 
 
//FastLED comes with several palettes pre-programmed.  I like purple a LOT, and so I added a custom purple palette.
 
const TProgmemPalette16 PurpleColors_p PROGMEM =
{
  CRGB::Purple,
  CRGB::Purple,
  CRGB::MidnightBlue,
  CRGB::MidnightBlue,

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by adafruit_support_carter on Thu Oct 12, 2017 6:04 pm

Who decided what Purple or MidnightBlue are?

The authors of FastLED. They are just going to be defined somewhere in their library. This might be it. I did a very quick scan of the code base, it could be buried somewhere else:
https://github.com/FastLED/FastLED/blob ... pes.h#L589

If the hex values are confusing or new to you, try giving this a read:
https://learn.adafruit.com/circuit-play ... ello-color

adafruit_support_carter
 
Posts: 3134
Joined: Tue Nov 29, 2016 2:45 pm

Re: Furscarf Code Editing

by jeremyzschau on Sat Oct 14, 2017 10:25 pm

I need to see an example. Anytime I try to edit the code I get verification errors.

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by franklin97355 on Sat Oct 14, 2017 11:00 pm

Anytime I try to edit the code I get verification errors.
Can you post the error messages?

franklin97355
 
Posts: 16635
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Furscarf Code Editing

by jeremyzschau on Sat Oct 14, 2017 11:23 pm

I need to see an example of the colors being edited.

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by adafruit_support_carter on Sat Oct 14, 2017 11:42 pm

Try replacing the definition of PurpleColors_p in the original sketch with the following lines of code:
Code: Select all | TOGGLE FULL SIZE
const TProgmemPalette16 PurpleColors_p PROGMEM =
{
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
 
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
 
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
 
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
};

Now you should get nothing but red. You'll need to press the button to cycle through the color palettes. The PurpleColors happens after OceanColors.

adafruit_support_carter
 
Posts: 3134
Joined: Tue Nov 29, 2016 2:45 pm

Re: Furscarf Code Editing

by jeremyzschau on Sun Oct 15, 2017 12:56 am

Thank you so much adafruit_support_carter! That has worked. I will upload the code after I try selecting my colors.

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by jeremyzschau on Sun Oct 15, 2017 2:49 am

Replacing with this code loses the different modes you can switch through. I tried replacing all with 0x7D7DFF but it only appears once then cycles through reds again.

What does the code look like when colors are changed and modes that can be switched through with a button on the gemma still remain?

adafruit_support_carter wrote:Try replacing the definition of PurpleColors_p in the original sketch with the following lines of code:
Code: Select all | TOGGLE FULL SIZE
const TProgmemPalette16 PurpleColors_p PROGMEM =
{
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
 
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
 
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
 
  0xFF0000,
  0xFF0000,
  0xFF0000,
  0xFF0000,
};

Now you should get nothing but red. You'll need to press the button to cycle through the color palettes. The PurpleColors happens after OceanColors.

jeremyzschau
 
Posts: 64
Joined: Fri Feb 27, 2015 11:00 pm

Re: Furscarf Code Editing

by adafruit_support_carter on Sun Oct 15, 2017 11:16 am

What does the code look like when colors are changed and modes that can be switched through with a button on the gemma still remain?

The original code should have done this. Did it not work?

adafruit_support_carter
 
Posts: 3134
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.