PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

122 lines
3.5KB

  1. #include <SmartMatrix.h>
  2. #include <FastLED.h>
  3. #define kMatrixWidth 32
  4. #define kMatrixHeight 32
  5. const bool kMatrixSerpentineLayout = false;
  6. #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
  7. CRGB leds[kMatrixWidth * kMatrixHeight];
  8. uint16_t XY( uint8_t x, uint8_t y)
  9. {
  10. uint16_t i;
  11. if( kMatrixSerpentineLayout == false) {
  12. i = (y * kMatrixWidth) + x;
  13. }
  14. if( kMatrixSerpentineLayout == true) {
  15. if( y & 0x01) {
  16. // Odd rows run backwards
  17. uint8_t reverseX = (kMatrixWidth - 1) - x;
  18. i = (y * kMatrixWidth) + reverseX;
  19. } else {
  20. // Even rows run forwards
  21. i = (y * kMatrixWidth) + x;
  22. }
  23. }
  24. return i;
  25. }
  26. // The 32bit version of our coordinates
  27. static uint16_t x;
  28. static uint16_t y;
  29. static uint16_t z;
  30. // We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
  31. // use the z-axis for "time". speed determines how fast time moves forward. Try
  32. // 1 for a very slow moving effect, or 60 for something that ends up looking like
  33. // water.
  34. // uint16_t speed = 1; // almost looks like a painting, moves very slowly
  35. uint16_t speed = 20; // a nice starting speed, mixes well with a scale of 100
  36. // uint16_t speed = 33;
  37. // uint16_t speed = 100; // wicked fast!
  38. // Scale determines how far apart the pixels in our noise matrix are. Try
  39. // changing these values around to see how it affects the motion of the display. The
  40. // higher the value of scale, the more "zoomed out" the noise iwll be. A value
  41. // of 1 will be so zoomed in, you'll mostly see solid colors.
  42. // uint16_t scale = 1; // mostly just solid colors
  43. // uint16_t scale = 4011; // very zoomed out and shimmery
  44. uint16_t scale = 31;
  45. // This is the array that we keep our computed noise values in
  46. uint8_t noise[kMatrixWidth][kMatrixHeight];
  47. void setup() {
  48. // uncomment the following lines if you want to see FPS count information
  49. // Serial.begin(38400);
  50. // Serial.println("resetting!");
  51. delay(3000);
  52. LEDS.addLeds<SMART_MATRIX>(leds,NUM_LEDS);
  53. LEDS.setBrightness(96);
  54. // Initialize our coordinates to some random values
  55. x = random16();
  56. y = random16();
  57. z = random16();
  58. // Show off smart matrix scrolling text
  59. pSmartMatrix->setScrollMode(wrapForward);
  60. pSmartMatrix->setScrollColor({0xff, 0xff, 0xff});
  61. pSmartMatrix->setScrollSpeed(15);
  62. pSmartMatrix->setScrollFont(font6x10);
  63. pSmartMatrix->scrollText("Smart Matrix & FastLED", -1);
  64. pSmartMatrix->setScrollOffsetFromEdge(10);
  65. }
  66. // Fill the x/y array of 8-bit noise values using the inoise8 function.
  67. void fillnoise8() {
  68. for(int i = 0; i < kMatrixWidth; i++) {
  69. int ioffset = scale * i;
  70. for(int j = 0; j < kMatrixHeight; j++) {
  71. int joffset = scale * j;
  72. noise[i][j] = inoise8(x + ioffset,y + joffset,z);
  73. }
  74. }
  75. z += speed;
  76. }
  77. void loop() {
  78. static uint8_t circlex = 0;
  79. static uint8_t circley = 0;
  80. static uint8_t ihue=0;
  81. fillnoise8();
  82. for(int i = 0; i < kMatrixWidth; i++) {
  83. for(int j = 0; j < kMatrixHeight; j++) {
  84. // We use the value at the (i,j) coordinate in the noise
  85. // array for our brightness, and the flipped value from (j,i)
  86. // for our pixel's hue.
  87. leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
  88. // You can also explore other ways to constrain the hue used, like below
  89. // leds[XY(i,j)] = CHSV(ihue + (noise[j][i]>>2),255,noise[i][j]);
  90. }
  91. }
  92. ihue+=1;
  93. // N.B. this requires SmartMatrix modified w/triple buffering support
  94. pSmartMatrix->fillCircle(circlex % 32,circley % 32,6,CRGB(CHSV(ihue+128,255,255)));
  95. circlex += random16(2);
  96. circley += random16(2);
  97. LEDS.show();
  98. // delay(10);
  99. }