2020-08-03 20:21:08 +02:00
// How to use this library with a FM6126 panel, thanks goes to:
// https://github.com/hzeller/rpi-rgb-led-matrix/issues/746
# include <Arduino.h>
2020-11-28 09:39:35 +01:00
# include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
2020-11-28 01:19:20 +01:00
# include <FastLED.h>
2020-08-03 20:21:08 +02:00
////////////////////////////////////////////////////////////////////
2020-11-28 01:19:20 +01:00
// FM6126 support is still experimental
2021-02-10 16:49:19 +01:00
// Output resolution and panel chain length configuration
# define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module.
# define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.
# define PANEL_CHAIN 1 // Total number of panels chained one to another
// placeholder for the matrix object
MatrixPanel_I2S_DMA * dma_display = nullptr ;
2020-08-03 20:21:08 +02:00
///////////////////////////////////////////////////////////////
2021-02-10 16:49:19 +01:00
// FastLED variables for pattern output
2020-12-07 12:13:09 +01:00
uint16_t time_counter = 0 , cycles = 0 , fps = 0 ;
unsigned long fps_timer ;
2020-08-03 20:21:08 +02:00
2020-11-28 01:19:20 +01:00
CRGB currentColor ;
CRGBPalette16 palettes [ ] = { HeatColors_p , LavaColors_p , RainbowColors_p , RainbowStripeColors_p , CloudColors_p } ;
CRGBPalette16 currentPalette = palettes [ 0 ] ;
2020-08-03 20:21:08 +02:00
2020-11-28 01:19:20 +01:00
CRGB ColorFromCurrentPalette ( uint8_t index = 0 , uint8_t brightness = 255 , TBlendType blendType = LINEARBLEND ) {
return ColorFromPalette ( currentPalette , index , brightness , blendType ) ;
}
2020-08-03 20:21:08 +02:00
2020-11-28 01:19:20 +01:00
void setup ( ) {
2021-02-10 16:49:19 +01:00
/*
The configuration for MatrixPanel_I2S_DMA object is held in HUB75_I2S_CFG structure ,
All options has it ' s predefined default values . So we can create a new structure and redefine only the options we need
Please refer to the ' 2 _PatternPlasma . ino ' example for detailed example of how to use the MatrixPanel_I2S_DMA configuration
if you need to change the pin mappings etc .
*/
HUB75_I2S_CFG mxconfig (
PANEL_RES_X , // module width
PANEL_RES_Y , // module height
PANEL_CHAIN // Chain length
) ;
mxconfig . driver = HUB75_I2S_CFG : : FM6126A ; // in case that we use panels based on FM6126A chip, we can set it here before creating MatrixPanel_I2S_DMA object
// OK, now we can create our matrix object
dma_display = new MatrixPanel_I2S_DMA ( mxconfig ) ;
2020-11-28 01:19:20 +01:00
// If you experience ghosting, you will need to reduce the brightness level, not all RGB Matrix
// Panels are the same - some seem to display ghosting artefacts at lower brightness levels.
// In the setup() function do something like:
2020-08-03 20:21:08 +02:00
2021-02-10 16:49:19 +01:00
// let's adjust default brightness to about 75%
dma_display - > setBrightness8 ( 96 ) ; // range is 0-255, 0 - 0%, 255 - 100%
// Allocate memory and start DMA display
if ( not dma_display - > begin ( ) )
Serial . println ( " ****** !KABOOM! Insufficient memory - allocation failed *********** " ) ;
2020-12-07 12:13:09 +01:00
fps_timer = millis ( ) ;
2021-02-10 16:49:19 +01:00
2020-08-03 20:21:08 +02:00
}
void loop ( ) {
2021-02-10 16:49:19 +01:00
for ( int x = 0 ; x < dma_display - > width ( ) ; x + + ) {
for ( int y = 0 ; y < dma_display - > height ( ) ; y + + ) {
2020-11-28 01:19:20 +01:00
int16_t v = 0 ;
uint8_t wibble = sin8 ( time_counter ) ;
v + = sin16 ( x * wibble * 3 + time_counter ) ;
v + = cos16 ( y * ( 128 - wibble ) + time_counter ) ;
v + = sin16 ( y * x * cos8 ( - time_counter ) / 8 ) ;
currentColor = ColorFromPalette ( currentPalette , ( v > > 8 ) + 127 ) ; //, brightness, currentBlendType);
2021-02-10 16:49:19 +01:00
dma_display - > drawPixelRGB888 ( x , y , currentColor . r , currentColor . g , currentColor . b ) ;
2020-11-28 01:19:20 +01:00
}
}
2020-12-07 12:13:09 +01:00
+ + time_counter ;
+ + cycles ;
+ + fps ;
2020-11-28 01:19:20 +01:00
if ( cycles > = 1024 ) {
time_counter = 0 ;
cycles = 0 ;
2020-12-01 17:28:17 +01:00
currentPalette = palettes [ random ( 0 , sizeof ( palettes ) / sizeof ( palettes [ 0 ] ) ) ] ;
2020-11-28 01:19:20 +01:00
}
2020-12-07 12:13:09 +01:00
// print FPS rate every 5 seconds
// Note: this is NOT a matrix refresh rate, it's the number of data frames being drawn to the DMA buffer per second
if ( fps_timer + 5000 < millis ( ) ) {
Serial . printf_P ( PSTR ( " Effect fps: %d \n " ) , fps / 5 ) ;
fps_timer = millis ( ) ;
fps = 0 ;
}
2020-08-03 20:21:08 +02:00
}