/* * Modified example copied from FastLED 3.0 Branch - originally written by Daniel Garcia * This example shows how to use some of FastLED's functions with the SmartMatrix Library * using the SmartMatrix buffers directly instead of FastLED's buffers. * FastLED's dithering and color balance features can't be used this way, but SmartMatrix can draw in * 36-bit color and so dithering may not provide much advantage. * * This example requires FastLED 3.0 or higher. If you are having trouble compiling, see * the troubleshooting instructions here: * https://github.com/pixelmatix/SmartMatrix/#external-libraries */ // uncomment one line to select your MatrixHardware configuration - configuration header needs to be included before //#include // SmartLED Shield for Teensy 3 (V4) #include // SmartLED Shield for Teensy 4 (V5) //#include // SmartMatrix Shield for Teensy 3 V1-V3 //#include // Teensy 4 Adapter attached to SmartLED Shield for Teensy 3 (V4) //#include // This file contains multiple ESP32 hardware configurations, edit the file to define GPIOPINOUT (or add #define GPIOPINOUT with a hardcoded number before this #include) //#include "MatrixHardware_Custom.h" // Copy an existing MatrixHardware file to your Sketch directory, rename, customize, and you can include it like this #include #include #include int led = 4; //led pin int i = 0; #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 = 32; // Set to the width of your display, must be a multiple of 8 const uint16_t kMatrixHeight = 32; // Set to the height of your display const uint8_t kRefreshDepth = 36; // 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); 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); SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions); // The 32bit version of our coordinates static uint16_t x; static uint16_t y; static uint16_t z; // We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll // use the z-axis for "time". speed determines how fast time moves forward. Try // 1 for a very slow moving effect, or 60 for something that ends up looking like // water. // uint16_t speed = 1; // almost looks like a painting, moves very slowly uint16_t speed = 20; // a nice starting speed, mixes well with a scale of 100 // uint16_t speed = 33; // uint16_t speed = 100; // wicked fast! // Scale determines how far apart the pixels in our noise matrix are. Try // changing these values around to see how it affects the motion of the display. The // higher the value of scale, the more "zoomed out" the noise iwll be. A value // of 1 will be so zoomed in, you'll mostly see solid colors. // uint16_t scale = 1; // mostly just solid colors // uint16_t scale = 4011; // very zoomed out and shimmery uint16_t scale = 31; // This is the array that we keep our computed noise values in uint8_t noise[kMatrixWidth][kMatrixHeight]; void setup() { Serial.begin(115200); //Begin Communication, no need for any address because this is the master Wire.begin(); pinMode(led, OUTPUT); // Enable printing FPS count information Serial.begin(115200); matrix.addLayer(&backgroundLayer); matrix.addLayer(&scrollingLayer); matrix.begin(); // Wait for Serial to be ready delay(1000); backgroundLayer.setBrightness(128); // Initialize our coordinates to some random values x = random16(); y = random16(); z = random16(); // Show off smart matrix scrolling text /*scrollingLayer.setMode(wrapForward); scrollingLayer.setColor({0xff, 0xff, 0xff}); scrollingLayer.setSpeed(15); scrollingLayer.setFont(font6x10); scrollingLayer.start("Fab Academy 2023", -1); scrollingLayer.setOffsetFromTop((kMatrixHeight/2) - 5); */ } // Fill the x/y array of 8-bit noise values using the inoise8 function. void fillnoise8() { for(int i = 0; i < kMatrixWidth; i++) { int ioffset = scale * i; for(int j = 0; j < kMatrixHeight; j++) { int joffset = scale * j; noise[i][j] = inoise8(x + ioffset,y + joffset,z); } } z += speed; } void loop() { Wire.requestFrom(1,64); //requesting 64 bytes from node1 while(Wire.available()){ int c = Wire.read(); if(c == 5){ Serial.println("Button on node1 was pressed"); static uint8_t circlex = 0; static uint8_t circley = 0; // if sketch uses swapBuffers(false), wait to get a new backBuffer() pointer after the swap is done: while(backgroundLayer.isSwapPending()); rgb24 *buffer = backgroundLayer.backBuffer(); static uint8_t ihue=0; fillnoise8(); for(int i = 0; i < kMatrixWidth; i++) { for(int j = 0; j < kMatrixHeight; j++) { // We use the value at the (i,j) coordinate in the noise // array for our brightness, and the flipped value from (j,i) // for our pixel's hue. buffer[kMatrixWidth*j + i] = (rgb24)CRGB(CHSV(noise[j][i],255,noise[i][j])); // You can also explore other ways to constrain the hue used, like below // buffer[kMatrixHeight*j + i] = CRGB(CHSV(ihue + (noise[j][i]>>2),255,noise[i][j])); } } ihue+=1; backgroundLayer.fillCircle(circlex % kMatrixWidth, circley % kMatrixHeight, 6, (rgb24)CRGB(CHSV(ihue+128,255,255))); circlex += random16(2); circley += random16(2); // buffer is filled completely each time, use swapBuffers without buffer copy to save CPU cycles backgroundLayer.swapBuffers(false); matrix.countFPS(); // print the loop() frames per second to Serial } } }