Spectacular lightworks

I am trying to make a very cool and therefore complicated LED lightworks. Is it possible to write the sketches in a special way that allows one part of the lightworks to function the same while I tweak the other parts?

I mean, if I want to keep one LED blinking on for a second and off a second, is there a way to write that once and then forget about it while I make the rest of the sketch?

Currently the way I understand it is that I have to integrate codes for that one LED into the rest of the sketch and that makes it complicated!

Is there a guide on complex light works?

Thanks!

You can write each effect as a function or class.
The keyword is “encapsulation”
This is a common technique, not limited to lighting.

Do I need to look for Arduino way of "encapsulation" or is it a general C way of writing stuff?

Could you point me to a arduino "encapsulation" how-to page pleae?

Thanks!

Do I need to look for Arduino way of "encapsulation" or is it a general C way of writing stuff?

I'm not aware there is an "Arduino way" - it's just C++.

uh, so programming with arduino IDE is actually C++?

Yup.

Some good tutorials and C++ reference here. http://www.cplusplus.com/doc/

Davidrules: Is there a guide on complex light works?

Every complex program consists of simple program statements and function calls.

I buid every Arduino program after the IPO programming model: - Input - Processing - Output

This is what you do in the loop, so every program in general looks like:

void setup() {
  // put initialization code here
}

void loop() {
  input();
  processing();
  output();
}

You just would have to write three functions by yourself; - input() function ==> read input/sensors/values/time from the outer world - processing() function ==> do all the programming logic that you need - output() function ==> send the results of your processing to the outer world

For all of it, use 'structured programming' with "data structures" accordingly to your needs and "algorithms" that work on the data structures.

So you can create complex programs from easy program statements and functions.

I mean, if I want to keep one LED blinking on for a second and off a second, is there a way to write that once and then forget about it while I make the rest of the sketch?

I've done some sound activated lighting effects... I don't exactly have some LEDs blinking independently from others, but I have a stereo effect where the left & right channels are independent.

So the program is built with several timers similar to the [u]Blink Without Delay[/u] example.

I have multiple "timers" with multiple LedState variables (actually a couple of type-longs where each bit represents the state of an LED), multiple previousMillis variables (such as previousMillis1) and various interval variables (such as interval1, etc.). There is only one currentMillis variable, because there is only one "current time".

I mostly avoid delay(), and it's a good idea to avoid delay() altogether because the program "freezes up" and can't do anything during the delay() time. But, I do use a couple of short delays where it doesn't hurt anything.

Then, there is a main loop and loops for each different lighting effect. Inside the loops, I call various functions. Some of the functions are only called depending on the various timers (or other variables). Like jurs, I have functions for reading the audio input, functions for manipulating the LED pattern (depending on timing and the audio, etc), and output functions that update the actual LED states.

... So, I have loops inside loops, multiple timers, and functions calling functions.