Comments (7)
Hello @Tornado-F5 I've made an updated version of moving_colored_bars
Let me know if this works any better for you!
from fastled_examples.
Modified code:
//***************************************************************
// Moving colored bars
// Original code by Richard Bailey, Feb. 2017
//
// Modified to allow a few other options (which might be
// useful for Christmas!)
// You'll probably need to adjust stuff for longer strips. I only
// tested with a tiny 32 pixel setup.
//
// Marc Miller, Dec 2017
//***************************************************************
#include "FastLED.h"
#define DATA_PIN 13
// #define CLK_PIN 13
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 17
#define BRIGHTNESS
CRGBArray<NUM_LEDS> leds;
#define FRAME_DELAY 80 //How fast to move (milliseconds)
/* Specify your colors and the order of those colors.
You can create a longer section of a single color by
listing it several times (such as green in this first
example)
Note: I used Grey instead of White here so it's not
as bright compared to the other colors.
*/
long colorPallet[] = {CRGB::Green,CRGB::Cyan,CRGB::Green,CRGB::Cyan,CRGB::Green,CRGB::Cyan,CRGB::Green,CRGB::Cyan,CRGB::Green,CRGB::Cyan,};
//long colorPallet[] = {CRGB::Black,CRGB::Green,CRGB::Red};
//long colorPallet[] = {CRGB::Green,CRGB::Red};
//long colorPallet[] = {CRGB::Black,CRGB::Blue,CRGB::Yellow,CRGB::Purple}; //Black can be used too of course.
const int numberofColors = sizeof(colorPallet)/sizeof(int); //Auto calculate your specified number of color bars
/* Play with setting the colorBarLength in different ways for slightly different effects. */
int colorBarLength = 10; //Some specific length
//int colorBarLength = NUM_LEDS-1; //The full strip length per color
//int colorBarLength = NUM_LEDS/2; //Half the strip length per color
//int colorBarLength = NUM_LEDS/numberofColors; //Strip length divided by number of colors
int frameCounter; //These don't need to be changed
int palletPosition;
int colorBarPosition = 1;
bool clearLEDS = false;
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(1500); // startup delayCLK_PIN
//FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
Serial.println("Setup done. \n");
}
//---------------------------------------------------------------
void loop() {
EVERY_N_MILLISECONDS(FRAME_DELAY) {
for (int x=0; x<NUM_LEDS-1; x++)
{
leds[x] = leds[x+1];
}
if (clearLEDS)
{
leds[NUM_LEDS-1] = colorPallet[palletPosition];
}
if ((colorBarPosition <= colorBarLength) && !clearLEDS)
{
leds[NUM_LEDS-1] = colorPallet[palletPosition];
colorBarPosition++;
}
if ((palletPosition == numberofColors-1) && (colorBarPosition > colorBarLength) && !clearLEDS)
{
leds[NUM_LEDS-1]=colorPallet[palletPosition];
palletPosition = 0;
colorBarPosition = 1;
clearLEDS= true;
}
if ((colorBarPosition > colorBarLength) && !clearLEDS)
{
colorBarPosition = 1;
palletPosition = palletPosition+1;
}
//if (clearLEDS && !leds(0,NUM_LEDS-1)) //Not using this for of test any more
if (clearLEDS && leds[0]==(CRGB)(colorPallet[numberofColors-1])) //restarts as soon as last color makes it past the end
{
//Serial.print( leds[0].r ); Serial.print("\t"), Serial.print( leds[0].g ); Serial.print("\t"), Serial.println( leds[0].b ); //Print out RGB colors it's triggering on
clearLEDS = false;
}
}//end_EVERY_N
FastLED.show();
}//end_main_loop
//---------------------------------------------------------------
//TODO:
// Add option to run in reverse direction
// Make some hot chocolate
from fastled_examples.
Have you tried simply listing the two colors like this?
long colorPallet[] = {CRGB::Green,CRGB::Cyan};
There's no reason to repeat them so many times if you're not doing something unique with the pattern.
And what happens if you change colorBarLength to 8?
from fastled_examples.
I have tried that, but if I have them only one, the strip will go green and cyan once, an d then start changing into other colors.
The colorBarLength 8 makes the bars shorter but still won't fix the color issue's
from fastled_examples.
I may have messed something up. Won't be able to test/look into it for a number of days though.
from fastled_examples.
Thats fine, take your time. Just let me know when you have figured it out!
from fastled_examples.
Closing for now. Comment again if you run into an issue.
from fastled_examples.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastled_examples.