Skip to content

Introduction

Milan edited this page Feb 10, 2021 · 4 revisions

An effect is a method that is run to change what is displayed on a specific LED strip.

Running of the effect is handled by the main loop switch-case statement. Obtaining information about what effect to set is handled by the current communication interface.

An effect is comprise of two files - the header file, containing the declaration, and the c++ file, containing the implementation.

Remember that only certain effect parameters are allowed.

Fastled.show() is called within the main loop and should not be called within an effect.

Sections

The Declaration

Before declaring your effect, remember to add an include guard. You'll also need to include the FastLED header.

#ifndef EFFECTNAME_H
#define EFFECTNAME_H

#include <FastLED.h>
...
#endif // EFFECTNAME_H

After including relevant headers, you'll have to register your effect name. To do this, add the following define:

#define EFFECTNAME EFFECT

Replace EFFECTNAME with the name of the effect you wish to register. This is the name that is used to select the effect.

For example, if the effect name was set as SOLIDCOLOR, if the communication interface received solidcolor as the name of the effect to run, the hash of this is used in the switch-case statement to call the effect's run method. This define is just telling the preprocessor what string to hash and add as this effect's switch-case.

Now, you'll need to create a class for your effect.

class EffectName
{
public:
    static void run();
};

Remember to make the run method public; this is the method that is called to actually run your effect. You'll later setup the parameters for this method. You can only use specific parameters.

The Implementation

Firstly, we need to include the FastLED header, as well as our declaration header. We may also need to include the led_util header. Then we just add the implementation for our declared methods.

#include <FastLED.h>
#include "led_util.h"
#include "effect_name.h"

void EffectName::run()
{
}

Registering the Effect

To register the effect, just take your .h and your .cpp files, and place them in src/effects.

That's it! The preprocessor handles the rest for you.

Clone this wiki locally