I have diced up Cylon until I got a desired effect but now when I try to addGlitter to void setup() I get errors. What is the proper way to insert this code into Cylon setup as I don't want it to loop.
Please post your full sketch. If possible, you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. After clicking the "Reply" button, you will see an "Attachments and other settings" link.
Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.
When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.
When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the forum toolbar).
I have changed Cylon Example to my desired effect:
#include <FastLED.h>
#define LED_TYPE NEOPIXEL
#define NUM_LEDS 30
#define DATA_PIN 5
#define FRAMES_PER_SECOND 120
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(57600);
Serial.println("resetting");
FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS);
FastLED.setBrightness(120);
static uint8_t hue = 0;
Serial.print("x");
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(0,0,100);
FastLED.show();
fadeall();
delay(120);
}
Serial.print("x");
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(0,0,138);
FastLED.show();
fadeall();
delay(75);
}
Serial.print("x");
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(0,0,177);
FastLED.show();
fadeall();
delay(50);
}
Serial.print("x");
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(0,0,216);
FastLED.show();
fadeall();
delay(40);
}
Serial.print("x");
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(0,0,255);
FastLED.show();
fadeall();
delay(30);
}
Serial.print("x");
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
leds[i] = CHSV(128, 255, 255);
FastLED.show();
fadeall();
delay(40);
}
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void loop() {
static uint8_t hue = 0;
Serial.print("x");
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(128, 255, 255);
FastLED.show();
fadeall();
delay(115);
}
Serial.print("x");
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
leds[i] = CHSV(128, 255, 255);
FastLED.show();
fadeall();
delay(115);
}
}
This code works great until i try to add glitter to it. Ive been reading about variables and scopes for hours and have been dicing up the codes and cross referencing them for days but i cant seem to get glitter to work at all let alone within the void setup. Ive seen glitter work perfectly in another FastLED example perfectly but no matter how hard i try i cant seem to get it to work.
this is raw glitter:
#include "FastLED.h"
#define LEDPIN 5
#define LED_TYPE NEOPIXEL
#define NUM_LEDS 30
#define BRIGHTNESS 60
#define FRAMES_PER_SECOND 120
CRGB leds[NUM_LEDS];
void setup() {
//sanity delay
delay(3000);
// set up LED strip info
FastLED.addLeds<LED_TYPE,LEDPIN>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
//changing the third variable changes how quickly the lights fade
fadeToBlackBy( leds, NUM_LEDS, 10);
//changing this variable will increase the chance of a "star" popping up
addGlitter(30);
FastLED.show();
}
//glitter effect
void addGlitter( fract8 chanceOfGlitter) {
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;}
}
so how do i add glitter to my cylon code?
Please read: Read this before posting a programming question .... Pay particular attention to Item #6 on how to properly post your code using Code Tags. Then re-post your code correctly.
Duplicate post of How to addGlitter to Cylon (FastLED Examples) - Programming Questions - Arduino Forum
Reported to moderator.
Fixed the coding layout. this is a new thread of the old post as requested.
Are you saying the two codes you posted work but when combined into a single code they don't? If that's the case post your attempt at combining them and define what you mean by "doesn't work". Describe the behavior you want, the actual behavior you observe, and the difference between the two.
i cant post that because ive tried nearly 100 different combinations trying to figure it out. its not a difficult project by all means so im simply asking how to properly put glitter in to my main project. and yes they both work separately and not combined.
Post your best attempt. What's so difficult about that?
Then pick one of the "nearly 100" that you tried and post that. Then we can see what it is that you're doing and probably why you've broken it.
The instructions at Merging Code are nicely detailed. See if they help.
Steve
glitter is a very small code. can someone just show me how to slam it into the main thing? all the other details i can work out as usual. i just cant get the damn glitter inside the lights!!
What have you tried?
MitchComer_YT:
can someone just show me how to slam it into the main thing?
Yes they can. But what do you learn from that? Notice how everyone is asking what you tried, because they want to see that you at least put some effort in yourself before offering help. So, can you show us your code? You said you had about 100 different iterations, try posting one.
what you have to do is every time before you do a .show() from within any of the cylon loops you have to call addGlitter() as such
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
leds[i] = CHSV(128, 255, 255);
addGlitter(30);
FastLED.show();
fadeall();
delay(40);
}
you haven't posted the fadeToBlackBy( leds, NUM_LEDS, 10); function which is used in the raw glitter example.