Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single codebase for both SmartMatrix and FastLED #20

Draft
wants to merge 7 commits into
base: AnimARTrix_SmartMatrix
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions AnimARTrix_SmartMatrix.ino → ANIMartRIX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,44 @@ License CC BY-NC 3.0

*/

#include <MatrixHardware_Teensy4_ShieldV5.h> // SmartLED Shield for Teensy 4 (V5)
#include <SmartMatrix.h>
#include <FastLED.h>

#ifdef ESP32
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this check

#define USE_SMARTMATRIX // Comment/remove this line to swap back to FastLED
#endif

#define num_x 32 // how many LEDs are in one row?
#define num_y 32 // how many rows?
#define brightness 255 // please be aware that reducing brightness also reduces color resolution, use only in emergency
// #define brightness 255 // please be aware that reducing brightness also reduces color resolution, use only in emergency

#define radial_filter_radius 23.0; // on 32x32, use 11 for 16x16

#define COLOR_DEPTH 24 // Choose the color depth used for storing pixels in the layers: 24 or 48 (24 is good for most sketches - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24)
const uint16_t kMatrixWidth = num_x; // Set to the width of your display, must be a multiple of 8
const uint16_t kMatrixHeight = num_y; // Set to the height of your display
const uint8_t kRefreshDepth = 48; // Tradeoff of color quality vs refresh rate, max brightness, and RAM usage. 36 is typically good, drop down to 24 if you need to. On Teensy, multiples of 3, up to 48: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48. On ESP32: 24, 36, 48
const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save RAM, more to keep from dropping frames and automatically lowering refresh rate. (This isn't used on ESP32, leave as default)
const uint8_t kPanelType = SM_PANELTYPE_HUB75_32ROW_MOD16SCAN; // Choose the configuration that matches your panels. See more details in MatrixCommonHub75.h and the docs: https://github.com/pixelmatix/SmartMatrix/wiki
const uint32_t kMatrixOptions = (SM_HUB75_OPTIONS_NONE); // see docs for options: https://github.com/pixelmatix/SmartMatrix/wiki
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);

//#define NUM_LEDS ((num_x) * (num_y))
CRGB leds[num_x * num_y]; // framebuffer
#ifdef USE_SMARTMATRIX
#ifdef ESP32
#include <MatrixHardware_ESP32_V0.h> // ESP32
#else
#include <MatrixHardware_Teensy4_ShieldV5.h> // SmartLED Shield for Teensy 4 (V5)
#endif

#include <SmartMatrix.h>

#define COLOR_DEPTH 24 // Choose the color depth used for storing pixels in the layers: 24 or 48 (24 is good for most sketches - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24)
const uint8_t kRefreshDepth = 48; // Tradeoff of color quality vs refresh rate, max brightness, and RAM usage. 36 is typically good, drop down to 24 if you need to. On Teensy, multiples of 3, up to 48: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48. On ESP32: 24, 36, 48
const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save RAM, more to keep from dropping frames and automatically lowering refresh rate. (This isn't used on ESP32, leave as default)
const uint8_t kPanelType = SM_PANELTYPE_HUB75_32ROW_MOD16SCAN; // Choose the configuration that matches your panels. See more details in MatrixCommonHub75.h and the docs: https://github.com/pixelmatix/SmartMatrix/wiki
const uint32_t kMatrixOptions = (SM_HUB75_OPTIONS_NONE); // see docs for options: https://github.com/pixelmatix/SmartMatrix/wiki
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
rgb24 *buffer = backgroundLayer.backBuffer();
#else
#define NUM_LEDS ((num_x) * (num_y))
CRGB buffer[num_x * num_y]; // framebuffer
#endif

float polar_theta[num_x][num_y]; // look-up table for polar angles
float distance[num_x][num_y]; // look-up table for polar distances
Expand Down Expand Up @@ -106,17 +120,21 @@ float show1, show2, show3, show4, show5, show6, show7, show8, show9, show0;

void setup() {

// FastLED.addLeds<NEOPIXEL, 13>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, 11, 13, BGR, DATA_RATE_MHZ(12)>(leds, NUM_LEDS);
// FastLED.setMaxPowerInVoltsAndMilliamps( 5, 2000); // optional current limiting [5V, 2000mA]

Serial.begin(115200); // check serial monitor for current fps count

render_polar_lookup_table((num_x / 2) - 0.5, (num_y / 2) - 0.5); // precalculate all polar coordinates
// polar origin is set to matrix centre

#ifdef USE_SMARTMATRIX // polar origin is set to matrix centre
matrix.addLayer(&backgroundLayer);
matrix.setBrightness(brightness);
// matrix.setBrightness(brightness);
matrix.begin();
#else
// FastLED.addLeds<NEOPIXEL, 13>(leds, NUM_LEDS);
FastLED.addLeds<APA102, 11, 13, BGR, DATA_RATE_MHZ(12)>(buffer, NUM_LEDS);
// FastLED.setMaxPowerInVoltsAndMilliamps( 5, 2000); // optional current limiting [5V, 2000mA]
// FastLED.setBrightness(brightness);
#endif
}

//*******************************************************************************************************************
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Great, please reach out to me and together we'll find a fair licensing solution

--------------------------------------------------------------------------------------------

Installation: Unzip and install all .ino files in one folder and run AnimARTrix_SmartMatrix.ino
Installation: Unzip and install all .ino files in one folder and run ANIMartRIX.ino

Either comment out of remove the #define USE_SMARTMATRIX to switch between SmartMatrix and FastLED output

--------------------------------------------------------------------------------------------

Expand All @@ -50,6 +52,7 @@ A big thank you to Sutaburosu, Antti Yliniemi, Yves Bazin & Marc Miller for the

[FastLED](https://github.com/FastLED/FastLED)

## Optional Software:
[SmartMatrix](https://github.com/pixelmatix/SmartMatrix)


Expand Down
Loading