5 Commits

22 changed files with 521 additions and 274 deletions

View File

@@ -1,5 +1,21 @@
<img src="images/terrible logo.png" width="300" height="175"/><h1>Grand Unified LED Logic Software (G.U.L.L.S.)</h1>
Tested
- Basic CLED Strip
- Basic CLED Matrix
- Basic Logical Matrix
- AlternateStrip
- AlternateMatrix
- CollisionStrip
- CollisionMatrix
- ColorRandomizerStrip (When used with ColorRandomizerMatrix, broken)
- ColorRanzomizerMatrix (When used with ColorRandomizerStrip, broken)
- CycleLightStrip
- CycleLightMatrix
- FluidColorMatrix
- RicochetMatrix (Broken)
*I need to write something here*
##### LED Hardware Development Status

128
diagram.json Normal file
View File

@@ -0,0 +1,128 @@
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{
"type": "wokwi-arduino-mega",
"id": "mega",
"top": 100,
"left": 100.78,
"attrs": {
}
},
{
"id": "neopixels",
"type": "wokwi-led-strip",
"top": 0,
"left": 0,
"attrs": {
"pixels": "24"
}
},
{
"id": "matrix",
"type": "wokwi-led-matrix",
"top": -200,
"left": 750,
"attrs": {
"rows": "6",
"cols": "6",
"layout": "serpentine",
"pixelShape": "circle"
}
},
{
"id": "matrix2",
"type": "wokwi-led-matrix",
"top": -50,
"left": 750,
"attrs": {
"rows": "6",
"cols": "6",
"layout": "serpentine",
"pixelShape": "circle"
}
},
{
"id": "matrix3",
"type": "wokwi-led-matrix",
"top": 100,
"left": 750,
"attrs": {
"rows": "6",
"cols": "6",
"layout": "serpentine",
"pixelShape": "circle"
}
},
{
"id": "matrix4",
"type": "wokwi-led-matrix",
"top": 250,
"left": 750,
"attrs": {
"rows": "6",
"cols": "6",
"layout": "serpentine",
"pixelShape": "circle"
}
},
{
"id": "matrix5",
"type": "wokwi-led-matrix",
"top": 400,
"left": 750,
"attrs": {
"rows": "6",
"cols": "6",
"layout": "serpentine",
"pixelShape": "circle"
}
},
{
"id": "matrix6",
"type": "wokwi-led-matrix",
"top": 550,
"left": 750,
"attrs": {
"rows": "6",
"cols": "6",
"layout": "serpentine",
"pixelShape": "circle"
}
}
],
"connections": [
["mega:0", "$serialMonitor:TX", ""],
["mega:1", "$serialMonitor:RX", ""],
["mega:GND.2", "neopixels:VSS", "black"],
["mega:6", "neopixels:DIN", "green"],
["mega:5V", "neopixels:VDD", "red"],
["mega:7", "matrix:DIN", "yellow"],
["mega:5V", "matrix:VDD", "red"],
["mega:GND.3", "matrix:VSS", "black"],
["matrix:DOUT", "matrix2:DIN", "blue"],
["mega:5V", "matrix2:VDD", "red"],
["mega:GND.3", "matrix2:VSS", "black"],
["matrix2:DOUT", "matrix3:DIN", "blue"],
["mega:5V", "matrix3:VDD", "red"],
["mega:GND.3", "matrix3:VSS", "black"],
["matrix3:DOUT", "matrix4:DIN", "blue"],
["mega:5V", "matrix4:VDD", "red"],
["mega:GND.3", "matrix4:VSS", "black"],
["matrix4:DOUT", "matrix5:DIN", "blue"],
["mega:5V", "matrix5:VDD", "red"],
["mega:GND.3", "matrix5:VSS", "black"],
["matrix5:DOUT", "matrix6:DIN", "blue"],
["mega:5V", "matrix6:VDD", "red"],
["mega:GND.3", "matrix6:VSS", "black"]
],
"dependencies": {},
"serialMonitor": {
"collapse": false,
"convertEol": false,
"display": "always",
"newline": "lf"
}
}

View File

@@ -1,33 +0,0 @@
#ifndef ACTION_H
#define ACTION_H
#include "Arduino.h"
#include "functional"
#include "StreamEvent.h"
template <typename T>
class Action {
public:
Action(function<bool(StreamEvent*)> _funcEventMatchesAction, function<T*(StreamEvent*)> _funcInvokeAction,
function<void(Print*)> _funcDescribeAction) : funcEventMatchesAction(_funcEventMatchesAction),
funcInvokeAction(_funcInvokeAction), funcDescribeAction(_funcDescribeAction) {}
bool eventMatchesAction(StreamEvent* event) {
return funcEventMatchesAction(event);
}
void describeAction(Print* printStream) {
funcDescribeAction(printStream);
}
T* invokeAction(StreamEvent* event) {
return funcInvokeAction(event);
}
private:
function<bool(StreamEvent*)> funcEventMatchesAction;
function<T*(StreamEvent*)> funcInvokeAction;
function<void(Print*)> funcDescribeAction;
};
#endif

View File

@@ -2,17 +2,11 @@
#define CLEDCONTROLLERPHYSICALMATRIX_H
#include "LEDHAL2D.h"
enum ArrangementType {
HORIZONTALSCAN,
HORIZONTALSERPENTINE,
COLUMNSCAN,
COLUMNSERPENTINE
};
#include "ILEDArrangement.h"
class CLEDControllerPhysicalMatrix : public LEDHAL2D {
public:
CLEDControllerPhysicalMatrix(CLEDController* _controller, char* ledName, ArrangementType _arrangement,
CLEDControllerPhysicalMatrix(CLEDController* _controller, char* ledName, ILEDArrangement& _arrangement,
int16_t width, int16_t height): LEDHAL2D(width, height, ledName, true), controller(_controller), arrangement(_arrangement) {}
virtual ~CLEDControllerPhysicalMatrix() {}
@@ -33,25 +27,7 @@ class CLEDControllerPhysicalMatrix : public LEDHAL2D {
}
int16_t XY(int16_t x, int16_t y) {
if(arrangement == ArrangementType::HORIZONTALSCAN) {
return getWidth() * y + x;
} else if(arrangement == ArrangementType::COLUMNSCAN) {
return getHeight() * x + y;
} else if(arrangement == ArrangementType::HORIZONTALSERPENTINE) {
if(y & 0x1) {
return y * getWidth() + (getWidth() - 1 - x);
} else {
return y * getWidth() + x;
}
} else if(arrangement == ArrangementType::COLUMNSERPENTINE) {
if(x & 0x1) {
return x * getHeight() + (getHeight() - 1 - y);
} else {
return x * getHeight() + y;
}
} else {
return 0; //How did you get here?
}
return arrangement.XY(x, y, getWidth(), getHeight());
}
uint16_t getNumLEDs() {
@@ -60,13 +36,13 @@ class CLEDControllerPhysicalMatrix : public LEDHAL2D {
protected:
void updateLEDs() {
controller->showLeds();
controller->showLeds(255);
}
private:
CLEDController*
controller;
ArrangementType
ILEDArrangement&
arrangement;
};

View File

@@ -13,7 +13,7 @@ class CLEDControllerPhysicalStrip : public LEDHAL {
void setColor(int16_t pixel, CRGB color) { controller->leds()[pixel] = color; }
protected:
void updateLEDs() { controller->showLeds(); }
void updateLEDs() { controller->showLeds(255); }
private:

View File

@@ -17,7 +17,7 @@ class ColorRandomizerMatrix : public MatrixAnimation {
uint8_t _numColors, CRGB* _colors, ColorRandomizerType _type) :
MatrixAnimation(_matrix, _refName, _updateTime), numColors(_numColors),
colors(new CRGB[_numColors]), fade(_fade), colorRandomizerInt(0),
scale(DEFAULT_MATRIX_FADER) {
scale(DEFAULT_MATRIX_FADER), type(_type) {
for(uint8_t i = 0; i < _numColors; i++) {
colors[i] = _colors[i];
}

View File

@@ -1,41 +0,0 @@
#ifndef GULLSMANAGER_H
#define GULLSMANAGER_H
#include "Arduino.h"
#include "Action.h"
#include "LEDHAL.h"
#include "AnimationBase.h"
class GULLSManager {
public:
GULLSManager(Stream* _stream, uint16_t _maxHALs, uint16_t _maxAnimations,
uint16_t _maxResponseActions, uint16_t _maxAnimationBuilderActions);
bool addLEDHAL(LEDHAL* hal);
bool addAnimation(AnimationBase* animation);
bool addResponseAction(Action<char>* action);
bool addAnimationBuilderAction(Action<AnimationBase>* action);
void update();
private:
uint16_t
maxHALs,
maxAnimations,
maxResponseActions,
maxAnimationBuilderActions;
Stream*
stream;
LEDHAL**
hals;
AnimationBase**
animations;
Action<char>**
responseActions;
Action<AnimationBase>**
animationBuilderActions;
};
#endif

15
include/ILEDArrangement.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef ILEDARRANGEMENT_H
#define ILEDARRANGEMENT_H
#include <Arduino.h>
// Interface is not pure virtual
class ILEDArrangement {
public:
ILEDArrangement() {}
virtual ~ILEDArrangement() {}
virtual int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) = 0;
};
#endif

View File

@@ -21,7 +21,6 @@ class LEDHAL {
virtual void requestShow() { showRequested = true; }
//TODO UnifiedColor should have constants
virtual void clearLEDs() {
for(uint16_t i = 0; i < getNumLEDs(); i++) {
setColor(i, CRGB(0, 0, 0));

56
include/Manager.h Normal file
View File

@@ -0,0 +1,56 @@
#ifndef MANAGER_H
#define MANAGER_H
#include <Arduino.h>
#include <LinkedList.h>
#include <LEDHAL.h>
#include <AnimationBase.h>
class Manager {
public:
Manager() {}
virtual ~Manager() {} // TODO Cleanup linked lists?
void addLEDs(LEDHAL* hal) {
// TODO Duplicate name checks
ledHALs.add(hal);
}
LEDHAL* removeLEDsByName(char* name) {
for(uint16_t i = 0; i < ledHALs.size(); i++) {
if(strcmp(ledHALs.get(i)->getLEDName(), name) == 0) {
return ledHALs.remove(i);
}
}
}
void addAnimation(AnimationBase* animation) {
// TODO Duplicate name checks
animations.add(animation);
}
AnimationBase* removeAnimationByName(char* name) {
for(uint16_t i = 0; i < animations.size(); i++) {
return animations.remove(i);
}
}
void update() {
for(uint16_t i = 0; i < animations.size(); i++) {
animations.get(i)->update();
}
for(uint16_t i = 0; i < ledHALs.size(); i++) {
ledHALs.get(i)->show();
}
}
private:
LinkedList<LEDHAL*>
ledHALs;
LinkedList<AnimationBase*>
animations;
};
#endif

View File

@@ -9,7 +9,8 @@ class RicochetHelper {
RicochetHelper() {}
RicochetHelper(int16_t _startPosX, int16_t _startPosY, int16_t _width, int16_t _height,
CRGB _color) : currentX(_startPosX), currentY(_startPosY), width(_width),
height(_height), xDir(random(0, 101) > 51 ? -1 : 1), yDir(random(0, 100) > 51 ? -1 : 1) {}
height(_height), xDir(random(0, 101) > 51 ? -1 : 1), yDir(random(0, 100) > 51 ? -1 : 1),
color(_color) {}
int16_t getCurrentXPos() { return currentX; }
int16_t getCurrentYPos() { return currentY; }

24
include/ScanArrangement.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef SCANARRANGEMENT_H
#define SCANARRANGEMENT_H
#include "ILEDArrangement.h"
class ScanArrangement : public ILEDArrangement {
public:
ScanArrangement(bool _isColumnScan) : isColumnScan(_isColumnScan) {}
virtual ~ScanArrangement() {}
int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) {
if(isColumnScan) {
return height * x + y;
} else {
return width * y + x;
}
}
private:
bool
isColumnScan;
};
#endif

View File

@@ -0,0 +1,31 @@
#ifndef SERPENTINEARRANGEMENT_H
#define SERPENTINEARRANGEMENT_H
#include "ILEDArrangement.h"
class SerpentineArrangement : public ILEDArrangement {
public:
SerpentineArrangement(bool _isColumnSerpentine) : isColumnSerpentine(_isColumnSerpentine) {}
virtual ~SerpentineArrangement() {}
int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) {
if(isColumnSerpentine) {
if(x & 0x1) {
return x * height + (height - 1 - y);
} else {
return x * height + y;
}
} else {
if(y & 0x1) {
return y * width + (width - 1 - x);
} else {
return y * width + x;
}
}
}
private:
bool
isColumnSerpentine;
};
#endif

18
include/TerribleMap.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef TERRIBLEMAP_H
#define TERRIBLEMAP_H
#include <LinkedList.h>
template <typename K, typename V>
struct Entry {
K key;
V value;
};
template <typename K, typename V>
class TerribleMap {
private:
LinkedList<Entry<K,V>> mapList;
};
#endif

View File

@@ -0,0 +1,46 @@
#ifndef TILEDSERPENTINEARRANGEMENT_H
#define TILEDSERPENTINEARRANGEMENT_H
#include "ILEDArrangement.h"
class TiledSerpentineArrangement : public ILEDArrangement {
public:
TiledSerpentineArrangement(bool _isColumnSerpentine, bool _isVerticallyTiled,
int16_t _tileWidth, int16_t _tileHeight) : isColumnSerpentine(_isColumnSerpentine),
isVerticallyTiled(_isVerticallyTiled), tileWidth(_tileWidth), tileHeight(_tileHeight) {}
virtual ~TiledSerpentineArrangement() {}
int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) {
int16_t tileNumber = isVerticallyTiled ? y / tileHeight : x / tileHeight;
int16_t modX = x % tileWidth;
int16_t modY = y % tileHeight;
int16_t tilePosition = 0;
if(isColumnSerpentine) {
if (x & 0x1) {
tilePosition = modX * tileHeight + (tileHeight - 1 - modY);
} else {
tilePosition = modX * tileHeight + modY;
}
} else {
if (y & 0x1) {
tilePosition = modY * tileWidth + (tileWidth - 1 - modX);
} else {
tilePosition = modY * tileWidth + modX;
}
}
return tileWidth * tileHeight * tileNumber + tilePosition;
}
private:
bool
isColumnSerpentine,
isVerticallyTiled;
int16_t
tileWidth,
tileHeight;
};
#endif

View File

@@ -9,7 +9,31 @@
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = teensy36
default_envs = mega
[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps =
fastled/FastLED@3.10.1
pfeerick/elapsedMillis@^1.0.6
adafruit/Adafruit GFX Library@^1.11.9
arduino-libraries/SD@^1.3.0
apechinsky/MemoryFree@^0.3.0
ivanseidel/LinkedList@0.0.0-alpha+sha.dac3874d28
[env:mega]
platform = atmelavr
board = megaatmega2560
framework = arduino
lib_deps =
fastled/FastLED@3.10.1
pfeerick/elapsedMillis@^1.0.6
adafruit/Adafruit GFX Library@^1.11.9
arduino-libraries/SD@^1.3.0
apechinsky/MemoryFree@^0.3.0
ivanseidel/LinkedList@0.0.0-alpha+sha.dac3874d28
[common]
@@ -22,3 +46,5 @@ lib_deps =
pixelmatix/SmartMatrix@^4.0.3
pfeerick/elapsedMillis@^1.0.6
adafruit/Adafruit GFX Library@^1.11.9
apechinsky/MemoryFree@^0.3.0
ivanseidel/LinkedList@0.0.0-alpha+sha.dac3874d28

View File

@@ -1,11 +1,12 @@
#include "ColorRandomizerMatrix.h"
void ColorRandomizerMatrix::execute() {
Serial.println("In Execute");
if(fade && isFading) {
CRGB color;
if(colorRandomizerInt == 0) {
for(uint16_t i = 0; i < type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth(); i++) {
for(uint16_t i = 0; i < (type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth()); i++) {
if(type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER) {
color = matrix->getColor(0, i);
} else {
@@ -19,7 +20,7 @@ void ColorRandomizerMatrix::execute() {
colorRandomizerInt++;
} else if(colorRandomizerInt > 0 && colorRandomizerInt < scale + 1) {
for(uint16_t i = 0; i < type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth(); i++) {
for(uint16_t i = 0; i < (type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth()); i++) {
if(type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER) {
matrix->drawFastHLine(0, i, matrix->getWidth(), matrix->getColor(0, i) - fadingValues[i]);
} else {
@@ -33,14 +34,17 @@ void ColorRandomizerMatrix::execute() {
isFading = false;
}
} else {
Serial.println("Setup Colors");
uint8_t rand;
for(uint16_t i = 0; i < type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth(); i++) {
for(uint16_t i = 0; i < (type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth()); i++) {
rand = random(0, numColors);
if(type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER) {
Serial.println("Draw Horizontal");
matrix->drawFastHLine(0, i, matrix->getWidth(), colors[rand]);
} else {
Serial.println("Draw Vertical");
matrix->drawFastVLine(i, 0, matrix->getHeight(), colors[rand]);
}
}

View File

@@ -8,9 +8,9 @@ void ColorRandomizerStrip::execute() {
for(uint16_t i = 0; i < strip->getNumLEDs(); i++) {
color = strip->getColor(i);
fadingValues[i].red = (ceil((float)color.red/scale));
fadingValues[i].green = (ceil((float)color.green/scale));
fadingValues[i].blue = (ceil((float)color.blue/scale));
fadingValues[i].red = (uint8_t)(ceil((float)color.red/scale));
fadingValues[i].green = (uint8_t)(ceil((float)color.green/scale));
fadingValues[i].blue = (uint8_t)(ceil((float)color.blue/scale));
}
colorRandomizerInt++;

View File

@@ -1,127 +0,0 @@
#include "GULLSManager.h"
GULLSManager::GULLSManager(Stream* _stream, uint16_t _maxHALs, uint16_t _maxAnimations,
uint16_t _maxResponseActions, uint16_t _maxAnimationBuilderActions) {
stream = _stream;
maxHALs = _maxHALs;
maxAnimations = _maxAnimations;
maxResponseActions = _maxResponseActions;
maxAnimationBuilderActions = _maxAnimationBuilderActions;
hals = new LEDHAL*[maxHALs];
for(uint16_t i = 0; i < maxHALs; i++) {
hals[i] = nullptr;
}
animations = new AnimationBase*[maxAnimations];
for(uint16_t i = 0; i < maxAnimations; i++) {
animations[i] = nullptr;
}
responseActions = new Action<char>*[maxResponseActions];
for(uint16_t i = 0; i < maxResponseActions; i++) {
responseActions[i] = nullptr;
}
animationBuilderActions = new Action<AnimationBase>*[maxAnimationBuilderActions];
for(uint16_t i = 0; i < maxAnimationBuilderActions; i++) {
animationBuilderActions[i] = nullptr;
}
}
bool GULLSManager::addLEDHAL(LEDHAL* hal) {
for(uint16_t i = 0; i < maxHALs; i++) {
if(hals[i] == nullptr) {
hals[i] = hal;
return true;
}
}
return false;
}
bool GULLSManager::addAnimation(AnimationBase* animation) {
for(uint16_t i = 0; i < maxAnimations; i++) {
if(animations[i] == nullptr) {
animations[i] = animation;
return true;
}
}
return false;
}
bool GULLSManager::addResponseAction(Action<char>* action) {
for(uint16_t i = 0; i < maxResponseActions; i++) {
if(responseActions[i] == nullptr) {
responseActions[i] = action;
return true;
}
}
return false;
}
bool GULLSManager::addAnimationBuilderAction(Action<AnimationBase>* action) {
for(uint16_t i = 0; i < maxAnimationBuilderActions; i++) {
if(animationBuilderActions[i] == nullptr) {
animationBuilderActions[i] = action;
return true;
}
}
return false;
}
void GULLSManager::update() {
if(stream->available()) {
StreamEvent event(stream);
for(uint16_t i = 0; i < maxResponseActions; i++) {
if(responseActions[i] != nullptr) {
if(responseActions[i]->eventMatchesAction(&event)) {
stream->write(responseActions[i]->invokeAction(&event));
event.markHandled();
break;
}
}
}
if(!event.isHandled()) {
for(uint16_t i = 0; i < maxAnimationBuilderActions; i++) {
if(animationBuilderActions[i] != nullptr) {
if(animationBuilderActions[i]->eventMatchesAction(&event)) {
this->addAnimation(animationBuilderActions[i]->invokeAction(&event));
event.markHandled();
break;
}
}
}
}
if(!event.isHandled()) {
stream->print(F("ERROR: An event with code "));
stream->print(event.getCode());
stream->println(F(" was registered but went unprocessed by any actions!"));
}
}
for(uint16_t i = 0; i < maxAnimations; i++) {
if(animations[i] != nullptr) {
animations[i]->update();
}
}
for(uint16_t i = 0; i < maxHALs; i++) {
if(hals[i] != nullptr) {
hals[i]->show();
}
}
}

View File

@@ -9,18 +9,37 @@ void RicochetMatrix::initialize() {
randomSeed(random(0, 10000000));
balls[i] = new RicochetHelper(random(0, matrix->getWidth()), random(0, matrix->getHeight()),
matrix->getWidth(), matrix->getHeight(), colors[random(0, numColors)]);
Serial.print("Ball ");
Serial.println(i);
Serial.print("X ");
Serial.println(balls[i]->getCurrentXPos());
Serial.print("Y ");
Serial.println(balls[i]->getCurrentYPos());
Serial.print("CR ");
Serial.println(balls[i]->getCurrentColor().red);
Serial.print("CG ");
Serial.println(balls[i]->getCurrentColor().green);
Serial.print("CB ");
Serial.println(balls[i]->getCurrentColor().blue);
}
}
void RicochetMatrix::execute() {
Serial.println("Pre Clear");
matrix->clearLEDs();
Serial.println("Post Clear");
Serial.println("Positional Updates");
for(uint16_t i = 0; i < numBalls; i++) {
balls[i]->updatePositions();
matrix->drawPixel(balls[i]->getCurrentXPos(), balls[i]->getCurrentYPos(),
balls[i]->getCurrentColor());
}
Serial.println("Post Positional Updates");
Serial.println("Pre Request Show");
matrix->requestShow();
Serial.println("Post Request Show");
}

View File

@@ -1,59 +1,143 @@
#include <Arduino.h>
#include "MatrixHardware_Teensy3_ShieldV1toV3.h"
#include "SmartMatrix.h"
#include "FastLED.h"
#include "LEDHAL.h"
#include "LEDHAL2D.h"
#include "CLEDControllerPhysicalStrip.h"
#include "CLEDControllerPhysicalMatrix.h"
#include "SmartMatrixPhysicalMatrix.h"
#include "SerpentineArrangement.h"
#include "TiledSerpentineArrangement.h"
#include "MemoryFree.h"
#include "elapsedMillis.h"
#include "LogicalMatrix.h"
#include "AlternateStrip.h"
#include "AnimationBase.h"
#include "AlternateMatrix.h"
#include "CollisionStrip.h"
#include "CollisionMatrix.h"
#include "ColorRandomizerMatrix.h"
#include "ColorRandomizerStrip.h"
#include "CycleLightStrip.h"
#include "CycleLightMatrix.h"
#include "FluidColorMatrix.h"
#include "RicochetMatrix.h"
#define NUMLEDS 24
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 96; // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 64; // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 36; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = SMARTMATRIX_OPTIONS_BOTTOM_TO_TOP_STACKING; // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
#define WIDTH 6
#define HEIGHT 36
#define TILE_WIDTH 6
#define TILE_HEIGHT 6
CRGB leds[NUMLEDS];
CRGB leds2[NUMLEDS];
CRGB leds3[NUMLEDS];
CRGB leds2D[WIDTH * HEIGHT];
CRGB someColor(255, 255, 255);
CRGB rainbow[] = {CRGB::Red, CRGB::Orange, CRGB::Yellow, CRGB::Green, CRGB::Blue, CRGB::Purple};
LEDHAL* hal;
LEDHAL2D* hal2D;
LEDHAL2D* smHAL;
LogicalMatrix* lm1;
LogicalMatrix* lm2;
AnimationBase* animation;
AnimationBase* animationMatrix;
AnimationBase* animationMatrix2;
rgb24 canRGB24Translate(rgb24 color) {
color.red = 0;
uint16_t shiftNumber = 0;
return color;
}
SerpentineArrangement arrangement(false);
TiledSerpentineArrangement tileArrangement(false, true, TILE_WIDTH, TILE_HEIGHT);
elapsedMillis memoryPrintTimer;
void setup() {
Serial.begin(115200);
Serial.println("Hello World!");
CLEDController* controller = &FastLED.addLeds<NEOPIXEL, 6>(leds, NUMLEDS);
CLEDController* controller2d = &FastLED.addLeds<NEOPIXEL, 7>(leds2, NUMLEDS);
CLEDController* controller2D = &FastLED.addLeds<NEOPIXEL, 7>(leds2D, WIDTH * HEIGHT);
hal = new CLEDControllerPhysicalStrip(controller, "Test Strip");
hal2D = new CLEDControllerPhysicalMatrix(controller2d, "Test Matrix", ArrangementType::COLUMNSERPENTINE, 6, 4);
smHAL = new SmartMatrixPhysicalMatrix(&backgroundLayer, "Test SM Matrix", kMatrixWidth, kMatrixHeight);
hal2D = new CLEDControllerPhysicalMatrix(controller2D, "Test Matrix", arrangement, WIDTH, HEIGHT);
lm1 = new LogicalMatrix("LM1", hal2D, 0, 0, 6, HEIGHT / 2);
lm2 = new LogicalMatrix("LM2", hal2D, 0, HEIGHT / 2, 6, HEIGHT);
canRGB24Translate(someColor);
/*animation = new AlternateStrip(hal, "Alternate Strip", 150, rainbow, 6);
animation->enable();
animationMatrix = new AlternateMatrix(lm1, "Alternate Matrix", 150, rainbow, 6, AlternateType::HORIZONTAL_ALTERNATE);
animationMatrix->enable();
animationMatrix2 = new AlternateMatrix(lm2, "Alternate Matrix 2", 150, rainbow, 6, AlternateType::VERTICAL_ALTERNATE);
animationMatrix2->enable();
/*animation = new CollisionStrip(hal, "Collision Strip", 150, CRGB::Orange, CRGB::Green);
animation->enable();
animationMatrix = new CollisionMatrix(lm1, "Collision Matrix", 1000, CRGB::Orange, CRGB::Green, CollisionType::HORIZONTAL_COLLISION);
animationMatrix->enable();
animationMatrix2 = new CollisionMatrix(lm2, "Collision Matrix 2", 1000, CRGB::Orange, CRGB::Green, CollisionType::VERTICAL_COLLISION);
animationMatrix2->enable();
animation = new ColorRandomizerStrip(hal, "Color Randomizer Strip", 50, true, 6, rainbow);
animation->enable();
animationMatrix = new ColorRandomizerMatrix(lm1, "Color Randomizer Matrix", 300, false, 6, rainbow, ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER);
animationMatrix->enable();
animationMatrix2 = new ColorRandomizerMatrix(lm2, "Color Randomizer Matrix 2", 300, false, 6, rainbow, ColorRandomizerType::VERTICAL_COLORRANDOMIZER);
animationMatrix2->enable();
animation = new CycleLightStrip(hal, "Cycle Light Strip", 250, 6, rainbow);
animation->enable();
animationMatrix = new CycleLightMatrix(lm1, "Cycle Light Matrix", 250, rainbow, 6, CycleLightType::HORIZONTAL_CYCLELIGHT);
animationMatrix->enable();
animationMatrix2 = new CycleLightMatrix(lm2, "Cycle Light Matrix 2", 250, rainbow, 6, CycleLightType::VERTICAL_CYCLELIGHT);
animationMatrix2->enable();
animationMatrix = new FluidColorMatrix(lm1, "Fluid Color", 30, FluidColorType::PIXEL_BY_PIXEL_FLUIDCOLOR, FluidColorResolution::FULL_FLUIDCOLOR);
animationMatrix->enable();
animationMatrix2 = new FluidColorMatrix(lm2, "Fluid Color 2", 30, FluidColorType::VERTICAL_FLUIDCOLOR, FluidColorResolution::FULL_FLUIDCOLOR);
animationMatrix2->enable();*/
animationMatrix = new RicochetMatrix(hal2D, "Ricochet Matrix", 150, 10, rainbow, 6);
animationMatrix->enable();
}
void loop() {
// put your main code here, to run repeatedly:
/*for(uint8_t i = 0; i < NUMLEDS; i++) {
hal->setColor(i, rainbow[(i + shiftNumber) % 6]);
}*/
//animation->update();
animationMatrix->update();
//animationMatrix2->update();
/*for(uint16_t i = 0; i < WIDTH * HEIGHT; i++) {
hal2D->setColor(i, CRGB::Red);
delay(1000);
hal2D->requestShow();
hal2D->show();
}*/
/*
for(uint8_t i = 0; i < HEIGHT; i++) {
hal2D->drawFastHLine(0, i, WIDTH, rainbow[(i + shiftNumber) % 6]);
} */
/*for(uint8_t i = 0; i < HEIGHT / 2; i++) {
lm1->drawFastHLine(0, i, WIDTH, rainbow[(i + shiftNumber) % 6]);
lm2->drawFastHLine(0, HEIGHT / 2 - 1 - i, WIDTH, rainbow[(i + shiftNumber) % 6]);
}*/
hal->requestShow();
hal->show();
hal2D->requestShow();
hal2D->show();
//shiftNumber++;
if(memoryPrintTimer >= 1000) {
Serial.println(freeMemory());
memoryPrintTimer = 0;
}
}

5
wokwi.toml Normal file
View File

@@ -0,0 +1,5 @@
[wokwi]
version = 1
firmware = '.pio/build/mega/firmware.hex'
elf = '.pio/build/mega/firmware.elf'
gdbServerPort=3333