Guest User

Untitled

a guest
Nov 25th, 2023
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <FastLED.h>
  2. #include <FastLED_GFX.h>
  3. #include <FastLEDMatrix.h>
  4.  
  5. #define DATA_PIN 12
  6. #define COLOR_ORDER GRB
  7. #define CHIPSET WS2812B
  8.  
  9. #define MATRIX_WIDTH 32 // width of FastLED matrix
  10. #define MATRIX_HEIGHT 8 // height of matrix
  11. #define MATRIX_TYPE (MTX_MATRIX_BOTTOM + MTX_MATRIX_RIGHT + MTX_MATRIX_COLUMNS + MTX_MATRIX_ZIGZAG)
  12.  
  13. cFastLEDSingleMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> matrix;
  14.  
  15. const CRGB colors[] = {
  16. CRGB(255, 0, 0),
  17. CRGB(0, 255, 0),
  18. CRGB(0, 0, 255)
  19. };
  20.  
  21. void setMatrixBrightness(uint8_t brightness) {
  22. for (int i = 0; i < matrix.Size(); ++i) {
  23. matrix[0][i].setRGB(matrix[0][i].r * brightness / 5, matrix[0][i].g * brightness / 5, matrix[0][i].b * brightness / 5);
  24. }
  25. }
  26.  
  27. void setup() {
  28. // Initialize FastLED
  29. FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(matrix[0], matrix.Size());
  30.  
  31. // Set initial brightness
  32. setMatrixBrightness(4);
  33.  
  34. // Clear the matrix
  35. FastLED.clear(true);
  36.  
  37. // Configure matrix properties
  38. matrix.setTextWrap(false);
  39. setMatrixBrightness(5);
  40. matrix.setTextColor(colors[0]);
  41. }
  42.  
  43. int x = matrix.width();
  44. int pass = 0;
  45.  
  46. void loop() {
  47. matrix.fillScreen(0);
  48.  
  49. matrix.setCursor(x, 0);
  50. matrix.print(F("If you can read this you're too close"));
  51.  
  52. // Display the matrix
  53. FastLED.show();
  54. delay(50); // Adjust the delay for a comfortable scrolling speed
  55.  
  56. // Decrement x to scroll text to the right
  57. --x;
  58.  
  59. // Check if the text has moved beyond the left edge of the matrix
  60. if (x < -36 * 7) { // Adjusted for the longer text
  61. x = matrix.width();
  62. if (++pass >= 3) pass = 0;
  63. matrix.setTextColor(colors[pass]);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment