FastLED 3.9.15
Loading...
Searching...
No Matches
SmartMatrixSketch.h
Go to the documentation of this file.
1
2
6
7/* This example demos a rectangular LED matrix with moving noise.
8 It requires the SmartMatrix library in addition to FastLED.
9 This SmartMatrix library is only available on Teensy boards at the moment.
10 It can be found at https://github.com/pixelmatix/SmartMatrix
11*/
12
13
14#include <SmartMatrix.h>
15#include <FastLED.h>
16
17#define kMatrixWidth 32
18#define kMatrixHeight 32
19const bool kMatrixSerpentineLayout = false;
20
21#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
22
24
25
26uint16_t XY( uint8_t x, uint8_t y)
27{
28 uint16_t i;
29
30 if( kMatrixSerpentineLayout == false) {
31 i = (y * kMatrixWidth) + x;
32 }
33
34 if( kMatrixSerpentineLayout == true) {
35 if( y & 0x01) {
36 // Odd rows run backwards
37 uint8_t reverseX = (kMatrixWidth - 1) - x;
38 i = (y * kMatrixWidth) + reverseX;
39 } else {
40 // Even rows run forwards
41 i = (y * kMatrixWidth) + x;
42 }
43 }
44
45 return i;
46}
47
48// The 32bit version of our coordinates
49static uint16_t x;
50static uint16_t y;
51static uint16_t z;
52
53// We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
54// use the z-axis for "time". speed determines how fast time moves forward. Try
55// 1 for a very slow moving effect, or 60 for something that ends up looking like
56// water.
57// uint16_t speed = 1; // almost looks like a painting, moves very slowly
58uint16_t speed = 20; // a nice starting speed, mixes well with a scale of 100
59// uint16_t speed = 33;
60// uint16_t speed = 100; // wicked fast!
61
62// Scale determines how far apart the pixels in our noise matrix are. Try
63// changing these values around to see how it affects the motion of the display. The
64// higher the value of scale, the more "zoomed out" the noise iwll be. A value
65// of 1 will be so zoomed in, you'll mostly see solid colors.
66
67// uint16_t scale = 1; // mostly just solid colors
68// uint16_t scale = 4011; // very zoomed out and shimmery
69uint16_t scale = 31;
70
71// This is the array that we keep our computed noise values in
73
74void setup() {
75 // uncomment the following lines if you want to see FPS count information
76 // Serial.begin(38400);
77 // Serial.println("resetting!");
78 delay(3000);
80 FastLED.setBrightness(96);
81
82 // Initialize our coordinates to some random values
83 x = random16();
84 y = random16();
85 z = random16();
86
87 // Show off smart matrix scrolling text
88 pSmartMatrix->setScrollMode(wrapForward);
89 pSmartMatrix->setScrollColor({0xff, 0xff, 0xff});
90 pSmartMatrix->setScrollSpeed(15);
91 pSmartMatrix->setScrollFont(font6x10);
92 pSmartMatrix->scrollText("Smart Matrix & FastLED", -1);
93 pSmartMatrix->setScrollOffsetFromEdge(10);
94}
95
96// Fill the x/y array of 8-bit noise values using the inoise8 function.
97void fillnoise8() {
98 for(int i = 0; i < kMatrixWidth; i++) {
99 int ioffset = scale * i;
100 for(int j = 0; j < kMatrixHeight; j++) {
101 int joffset = scale * j;
102 noise[i][j] = inoise8(x + ioffset,y + joffset,z);
103 }
104 }
105 z += speed;
106}
107
108
109void loop() {
110 static uint8_t circlex = 0; // okay static in header
111 static uint8_t circley = 0; // okay static in header
112
113 static uint8_t ihue=0; // okay static in header
114 fillnoise8();
115 for(int i = 0; i < kMatrixWidth; i++) {
116 for(int j = 0; j < kMatrixHeight; j++) {
117 // We use the value at the (i,j) coordinate in the noise
118 // array for our brightness, and the flipped value from (j,i)
119 // for our pixel's hue.
120 leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
121
122 // You can also explore other ways to constrain the hue used, like below
123 // leds[XY(i,j)] = CHSV(ihue + (noise[j][i]>>2),255,noise[i][j]);
124 }
125 }
126 ihue+=1;
127
128 // N.B. this requires SmartMatrix modified w/triple buffering support
129 pSmartMatrix->fillCircle(circlex % 32,circley % 32,6,CRGB(CHSV(ihue+128,255,255)));
130 circlex += random16(2);
131 circley += random16(2);
132 FastLED.show();
133 // delay(10);
134}
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
void * pSmartMatrix
Pointer to the matrix object when using the Smart Matrix Library.
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
@ SMART_MATRIX
Definition FastLED.h:275
uint8_t noise[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.h:97
uint32_t z[NUM_LAYERS]
Definition Fire2023.h:93
fl::UISlider scale("Scale", 4,.1, 4,.1)
uint16_t speed
Definition Noise.ino:66
#define kMatrixSerpentineLayout
void setup()
void fillnoise8()
#define kMatrixHeight
uint16_t XY(uint8_t x, uint8_t y)
#define kMatrixWidth
void loop()
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition crgb.h:25
fl::u8 inoise8(fl::u16 x, fl::u16 y, fl::u16 z)
LIB8STATIC fl::u16 random16() FL_NOEXCEPT
Generate a 16-bit random number.
Definition random8.h:63