Skip to content
pup05 edited this page Sep 20, 2014 · 1 revision

It's usually more complicated to actually create the logic for new patterns than it is to add them to the Aurora Patterns menu. You can look at any of the Pattern*.h files for an example. We'll look at PatternInfinity.h, which is a fairly simple example:

#ifndef PatternInfinity_H

class PatternInfinity : public Drawable {
public:
    unsigned int drawFrame() {
        // dim all pixels on the display slightly 
        // to 250/255 (98%) of their current brightness
        effects.DimAll(250);

        // the Effects class has some sample oscillators
        // that move from 0 to 255 at different speeds
        effects.MoveOscillators();
        
        // the horizontal position of the head of the infinity sign
        // oscillates from 0 to the maximum horizontal and back
        int x = (MATRIX_WIDTH - 1) - effects.p[1];

        // the vertical position of the head oscillates
        // from 8 to 23 and back (hard-coded for a 32x32 matrix)
        int y = map8(sin8(effects.osci[3]), 8, 23);
        
        // the hue oscillates from 0 to 255, overflowing back to 0
        byte hue = sin8(effects.osci[5]);

        // draw a pixel at x,y using a color from the current palette
        effects.Pixel(x, y, hue);

        return 15;
    }
};

#endif

Compiling Aurora

Follow the instructions in Compiling to get started. When you're able to compile and upload Aurora to your display without any changes, you're ready to move on.

Create your pattern

  1. Create a new file that starts with Pattern (for consistency) and ends with your pattern name: PatternName.h
  2. Extend your class from Drawable.
  3. Include a drawFrame function, which draws a single frame as quickly as possible, without any calls to delay(), and returns the number of milliseconds to wait before drawing another frame. Return 30 to draw about 30 frames per second, for example.
  4. Save your file in the same directory as Aurora.ino.

Add your pattern to the Patterns menu

  1. Open Patterns.h
  2. Add a line including your new pattern file to the end of the list of includes: #include "PatternName.h"
  3. Add an instance of your class to the end of the list of patterns: PatternName name;
  4. Increase the PATTERN_COUNT constant value by one: static const int PATTERN_COUNT = 19;
  5. Finally, add your class instance to the end of the items list: &name,

Patterns.h should now look similar to this (only the changed parts included for brevity):

Includes list:

#include "PatternFlock.h"
...
#include "YourPatternFile.h"  

Class instance list:

class Patterns : public Playlist {
private:
    PatternFlock flock;
    ...
    YourPattern yourPattern;

Drawable item list:

static const int PATTERN_COUNT = 18;

Drawable* items[PATTERN_COUNT] = {  
&flock,  
...  
&yourPattern,

That's it, now connect your display to your computer, compile, and upload. Your pattern should now be at the end of the Patterns menu (click the < Left button on the remote once).

Clone this wiki locally