Hello Programmers, I am having a bit of a problem with my code here.

Hello Programmers,
I am having a bit of a problem with my code here. I was just wondering if anyone have an idea on how to solve this. I am using the Firstlight example code as a base for my program. And I am also using a rotary encode to change the delay in between the pixels.
And here is my problem, I would like to be able to set the delay as I do, but I would like a constant delay of 100ms for every pixel to go dark, regardless of what delay I set in between every pixel to light.
Anny idea or input on this?

if you’ve modified firstlight, then post your code. i’d suggest pastebin as google+ mucks up characters.

http://pastebin.com/8wtSJ8hd

Initially, your using delay… This is just bad!
Delay freezes the program, as allows nothing to happen until the delay is finished. This is fine for rudimentary coding, but will invariably cause issues later.

Better to use Millis() and start-delayrequired.

this was written nicely, and then one wrong keystroke and the whole lot disappears…! :: LOL ::

ok, this will work, but not to 100ms perfectly, but can be tweaked for preference. if you 100% need 100ms, then you need a timed loop. if you need something that looks like 100ms, this will do.

to the top variables add;

#define BRIGHTNESS 255
int fadeOut = 100-(BRIGHTNESS/12);

to the void setup() add;
FastLED.setBrightness(BRIGHTNESS);

to the void loop() add;
EVERY_N_MILLISECONDS( 10 ) { fadeToBlackBy(leds, NUM_LEDS, fadeOut); }

this sets the overall brightness, which is 255 by default, but allocates the fadeout speed. for this its set to 75, but the fade out speed is logarithmic so will need a tweak.

and then every 10 milliseconds, the brightness of the leds will drop by 65%

255, 165, 107, 70, 45, 29, 19, 12, 8, 5

when the encoder is moved, the delay will kick in and freeze everything, and then start fading again.

see if this works, and then if you want rid of the pauses we can work that out!

Thank you for your time and fast reply Kelvin. I am new at both Arduino, and pixels. So I really appreciate your input.
I tried your suggestions in my code. But I realize that I need the pixels to go distinctly black after about 100ms. The fading won’t really work. I need every pixel to stay lit for 100ms regardless if I set the delay in between every pixel to 5ms or 1000ms.
In your mind, is this a problem I need to address by removing the delay instruction? Or how do I go about this? Would I need to rewrite the whole code if not using the delay instruction?

Ack! My bad! I read fade out over 100ms, not stay on for 100ms!

I think the whole timing of the code needs to be looked at otherwise it’s just gonna cause you issues with every change you make.

I’m at work atm so won’t really be able to do anything :: LOL ::

Have a look at the arduino.cc tutorials on blink without delay for a start

But the premise is;

Start a timer;
Record what time it is at the beginning of your sequence;
Sequence runs / check if enough time has passed
If enough time has passed do something else

I will take a look at this tutorial. Thanx kelvin. You seem to bit of a wisard when it comes to code.

Ha! It took me 2 days to draw a circle! :slight_smile:

after burrowing into your code a little, you seem to have 2 leds, 1 dumb (pin 12), 1 addressable (pin 13)? is this redundant data from your oled example?

I am using the led connected to the number 12 pin as a marker for when the button has been pressed, and the loop is running. So that I know when I can press again. It’s just a nice and visual cue.
I am noticing that working without delay is a bit more challenging than the simple delay command. Much harder getting your head around the code.

Yep, I think that’s why they introduce you to delay and then add Millis later