Initial Commit
This commit is contained in:
38
include/Alternate.h
Normal file
38
include/Alternate.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef ALTERNATE
|
||||
#define ALTERNATE
|
||||
|
||||
#include "Animation.h"
|
||||
#include "GlobalSettings.h"
|
||||
#include "Utilities.h"
|
||||
#include <FastLED.h>
|
||||
|
||||
class Alternate : public Animation {
|
||||
public:
|
||||
Alternate(long _updateTime, uint16_t _alternateSize, CRGB* _colors, uint8_t _numColors) :
|
||||
Animation(_updateTime, 10 * _numColors), numColors(_numColors), colors(new CRGB[_numColors]),
|
||||
alternateInt(0), alternateSize(_alternateSize) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
void initialize(CRGB* leds) {
|
||||
alternateInt = 0;
|
||||
resetTimer();
|
||||
|
||||
Utilities::setAll(leds, NUMLEDS, CRGB::Black);
|
||||
}
|
||||
|
||||
void execute(CRGB* leds);
|
||||
private:
|
||||
uint16_t
|
||||
alternateInt,
|
||||
alternateSize;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
78
include/Animation.h
Normal file
78
include/Animation.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef ANIMATION
|
||||
#define ANIMATION
|
||||
|
||||
#include <FastLED.h>
|
||||
#include <elapsedMillis.h>
|
||||
#include "Utilities.h"
|
||||
|
||||
class Animation {
|
||||
public:
|
||||
Animation(long _updateTime, uint16_t _finishedAfterCycles) : updateTime(_updateTime),
|
||||
finishedAfterCycles(_finishedAfterCycles), cycles(0), enabled(false),
|
||||
initialized(false), timer(0) {}
|
||||
|
||||
virtual void initialize(CRGB* leds) {
|
||||
|
||||
}
|
||||
virtual void execute(CRGB* leds) {}
|
||||
virtual bool isFinished() {
|
||||
return cycles > finishedAfterCycles;
|
||||
}
|
||||
|
||||
void update(CRGB* leds) {
|
||||
if(enabled) {
|
||||
if(timer >= updateTime) {
|
||||
if(!initialized) {
|
||||
initialize(leds);
|
||||
cycles = 0;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
if(!isFinished()) {
|
||||
execute(leds);
|
||||
}
|
||||
|
||||
resetTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void enable() {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
void reinitialize() {
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
bool isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
protected:
|
||||
void resetTimer() {
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
void cycleCompleted() {
|
||||
cycles = cycles += 1;
|
||||
}
|
||||
|
||||
private:
|
||||
long
|
||||
updateTime;
|
||||
uint16_t
|
||||
cycles,
|
||||
finishedAfterCycles;
|
||||
bool
|
||||
enabled,
|
||||
initialized;
|
||||
elapsedMillis
|
||||
timer;
|
||||
};
|
||||
|
||||
#endif
|
||||
28
include/Collision.h
Normal file
28
include/Collision.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef COLLISION_H
|
||||
#define COLLISION_H
|
||||
|
||||
#include "Animation.h"
|
||||
#include "Utilities.h"
|
||||
#include "GlobalSettings.h"
|
||||
|
||||
class Collision : public Animation {
|
||||
public:
|
||||
Collision(long _updateTime, CRGB _color1, CRGB _color2) :
|
||||
Animation(_updateTime, 10), color1(_color1), color2(_color2) {}
|
||||
|
||||
void initialize(CRGB* leds) {
|
||||
collisionInt = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute(CRGB* leds);
|
||||
|
||||
private:
|
||||
uint16_t
|
||||
collisionInt;
|
||||
CRGB
|
||||
color1,
|
||||
color2;
|
||||
};
|
||||
|
||||
#endif
|
||||
36
include/CycleLight.h
Normal file
36
include/CycleLight.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef CYCLELIGHT_H
|
||||
#define CYCLELIGHT_H
|
||||
|
||||
#include "Animation.h"
|
||||
#include "GlobalSettings.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
class CycleLight : public Animation {
|
||||
public:
|
||||
CycleLight(long _updateTime, CRGB* _colors, uint8_t _numColors) :
|
||||
Animation(_updateTime, 3 * _numColors), colors(new CRGB[_numColors]),
|
||||
numColors(_numColors), cycleLightInt(0), cycleLightColor(0) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
void initialize(CRGB* leds) {
|
||||
cycleLightInt = 0;
|
||||
cycleLightColor = 0;
|
||||
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute(CRGB* leds);
|
||||
private:
|
||||
uint16_t
|
||||
cycleLightInt,
|
||||
cycleLightColor;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
};
|
||||
|
||||
#endif
|
||||
32
include/FluidColor.h
Normal file
32
include/FluidColor.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef FLUIDCOLOR_H
|
||||
#define FLUIDCOLOR_H
|
||||
|
||||
#include "Animation.h"
|
||||
#include "GlobalSettings.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
class FluidColor : public Animation {
|
||||
public:
|
||||
FluidColor(long _updateTime) : Animation(_updateTime, 15),
|
||||
colorShifter(0), colors(new CRGB[256]) {
|
||||
for(uint16_t i = 0; i < 256; i++) {
|
||||
colors[i] = CRGB(CHSV(i, 255, 255));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void initialize(CRGB* leds) {
|
||||
colorShifter = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute(CRGB* leds);
|
||||
private:
|
||||
uint16_t
|
||||
colorShifter;
|
||||
CRGB*
|
||||
colors;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
2
include/GlobalSettings.h
Normal file
2
include/GlobalSettings.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define OUTPUT_PIN 6
|
||||
#define NUMLEDS 42
|
||||
37
include/README
Normal file
37
include/README
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the convention is to give header files names that end with `.h'.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
20
include/Utilities.h
Normal file
20
include/Utilities.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef UTILITIES
|
||||
#define UTILITIES
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <FastLED.h>
|
||||
|
||||
class Utilities {
|
||||
public:
|
||||
static void setRange(CRGB* leds, uint16_t start, uint16_t end, CRGB color) {
|
||||
for(uint16_t i = start; i < end; i++) {
|
||||
leds[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
static void setAll(CRGB* leds, uint16_t numLEDs, CRGB color) {
|
||||
setRange(leds, 0, numLEDs, color);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user