Skip to content

Instantly share code, notes, and snippets.

@shadethegrey1
Created March 5, 2021 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadethegrey1/bdacfdd12b3654c83792e86be1de6383 to your computer and use it in GitHub Desktop.
Save shadethegrey1/bdacfdd12b3654c83792e86be1de6383 to your computer and use it in GitHub Desktop.
LED Scroller
#define USE_ADAFRUIT_GFX_LAYERS
#include <MatrixHardware_Teensy4_ShieldV5.h>
#include <SmartMatrix.h>
#include "gimpbitmap.h"
#include "colorwheel.c"
#include <Fonts/FreeMono12pt7b.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 uint16_t kMatrixWidth = 128; // 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);
const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer01, 34, 32, COLOR_DEPTH, kBackgroundLayerOptions);
SMARTMATRIX_ALLOCATE_GFX_MONO_LAYER(scrollingLayer00, kMatrixWidth, kMatrixHeight, kMatrixWidth*14, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
SMARTMATRIX_ALLOCATE_INDEXED_LAYER(indexedLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kIndexedLayerOptions);
int led = -1; // Set to -1 to disable LED flash, only needed for debugging purposes
//int led = 13; // builtin LED pin on the Teensy, interferes with refresh on Teensy 4
//Draw bitmap on backgroundlayer
void drawBitmap(int16_t x, int16_t y, const gimp32x32bitmap* bitmap) {
for(unsigned int i=0; i < bitmap->height; i++) {
for(unsigned int j=0; j < bitmap->width; j++) {
SM_RGB pixel = { bitmap->pixel_data[(i*bitmap->width + j)*3 + 0],
bitmap->pixel_data[(i*bitmap->width + j)*3 + 1],
bitmap->pixel_data[(i*bitmap->width + j)*3 + 2] };
if(COLOR_DEPTH == 48) {
pixel.red = pixel.red << 8;
pixel.green = pixel.green << 8;
pixel.blue = pixel.blue << 8;
}
backgroundLayer.drawPixel(x + j, y + i, pixel);
}
}
}
// Draw bitmap on backgroundlayer01
void drawBitmap01(int16_t x, int16_t y, const gimp32x32bitmap* bitmap) {
for(unsigned int i=0; i < bitmap->height; i++) {
for(unsigned int j=0; j < bitmap->width; j++) {
SM_RGB pixel = { bitmap->pixel_data[(i*bitmap->width + j)*3 + 0],
bitmap->pixel_data[(i*bitmap->width + j)*3 + 1],
bitmap->pixel_data[(i*bitmap->width + j)*3 + 2] };
if(COLOR_DEPTH == 48) {
pixel.red = pixel.red << 8;
pixel.green = pixel.green << 8;
pixel.blue = pixel.blue << 8;
}
backgroundLayer01.drawPixel(x + j, y + i, pixel);
}
}
}
//Function being worked on
//void marquee
void setup() {
matrix.addLayer(&backgroundLayer);
matrix.addLayer(&scrollingLayer00);
matrix.addLayer(&backgroundLayer01);
matrix.addLayer(&indexedLayer);
matrix.setBrightness(20);
matrix.begin();
}
void loop() {
int x, y;
backgroundLayer.fillScreen({0,0,0});
drawBitmap01(0, 0, (const gimp32x32bitmap*)&colorwheel);
backgroundLayer01.swapBuffers();
scrollingLayer00.resizeLayer(0,32);
scrollingLayer00.setMode(wrapForwardFromLeft);
scrollingLayer00.setStartOffsetFromLeft(128);
scrollingLayer00.setColor({0x00, 0XFF, 0x00});
scrollingLayer00.setSpeed(90);
scrollingLayer00.setFont(&FreeMono12pt7b);
scrollingLayer00.setRotation(0);
scrollingLayer00.setOffsetFromTop((kMatrixHeight/2) - 10);
scrollingLayer00.start("THIS IS A TEST FOR WHAT I AM GOING TO DO !", 1);
while(scrollingLayer00.getStatus());
scrollingLayer00.setMode(wrapForward);
scrollingLayer00.start("This is the second scroll test", 1);
while(scrollingLayer00.getStatus());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment