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