FastLED 3.9.15
Loading...
Searching...
No Matches
Noise.ino
Go to the documentation of this file.
1
4
5#include <FastLED.h>
6
7// Uncomment to enable a slowly cycling base hue
8// #define USE_HUE
9
10//
11// Mark's xy coordinate mapping code. See the XYMatrix for more information on it.
12//
13
14// Params for width and height
15#if defined(__AVR_ATtinyxy4__)
16// Tiny 4x4 matrix for this memory constrained device.
17const uint8_t kMatrixWidth = 8;
18const uint8_t kMatrixHeight = 8;
19#else
20const uint8_t kMatrixWidth = 16;
21const uint8_t kMatrixHeight = 16;
22#endif
23
24#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
25#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
26
27// Param for different pixel layouts
28const bool kMatrixSerpentineLayout = true;
29
30
31uint16_t XY( uint8_t x, uint8_t y)
32{
33 uint16_t i;
34
35 if( kMatrixSerpentineLayout == false) {
36 i = (y * kMatrixWidth) + x;
37 }
38
39 if( kMatrixSerpentineLayout == true) {
40 if( y & 0x01) {
41 // Odd rows run backwards
42 uint8_t reverseX = (kMatrixWidth - 1) - x;
43 i = (y * kMatrixWidth) + reverseX;
44 } else {
45 // Even rows run forwards
46 i = (y * kMatrixWidth) + x;
47 }
48 }
49
50 return i;
51}
52
53// The leds
55
56// The 32bit version of our coordinates
57static uint16_t x;
58static uint16_t y;
59static uint16_t z;
60
61// We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
62// use the z-axis for "time". speed determines how fast time moves forward. Try
63// 1 for a very slow moving effect, or 60 for something that ends up looking like
64// water.
65// uint16_t speed = 1; // almost looks like a painting, moves very slowly
66uint16_t speed = 20; // a nice starting speed, mixes well with a scale of 100
67// uint16_t speed = 33;
68// uint16_t speed = 100; // wicked fast!
69
70// Scale determines how far apart the pixels in our noise matrix are. Try
71// changing these values around to see how it affects the motion of the display. The
72// higher the value of scale, the more "zoomed out" the noise iwll be. A value
73// of 1 will be so zoomed in, you'll mostly see solid colors.
74
75// uint16_t scale = 1; // mostly just solid colors
76// uint16_t scale = 4011; // very zoomed out and shimmery
77uint16_t scale = 311;
78
79// This is the array that we keep our computed noise values in
81
82void setup() {
83 // uncomment the following lines if you want to see FPS count information
84 // Serial.begin(38400);
85 // Serial.println("resetting!");
86 delay(3000);
87 FastLED.addLeds<WS2811,2,RGB>(leds,NUM_LEDS);
88 FastLED.setBrightness(96);
89
90 // Initialize our coordinates to some random values
91 x = random16();
92 y = random16();
93 z = random16();
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 < MAX_DIMENSION; i++) {
99 int ioffset = scale * i;
100 for(int j = 0; j < MAX_DIMENSION; 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#ifdef USE_HUE
111 static uint8_t ihue=0;
112#endif
113 fillnoise8();
114 for(int i = 0; i < kMatrixWidth; i++) {
115 for(int j = 0; j < kMatrixHeight; j++) {
116 // We use the value at the (i,j) coordinate in the noise
117 // array for our brightness, and the flipped value from (j,i)
118 // for our pixel's hue.
119#ifdef USE_HUE
120 // Slowly cycling base hue plus noise-derived offset
121 leds[XY(i,j)] = CHSV(ihue + (noise[j][i]>>2),255,noise[i][j]);
122#else
123 leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
124#endif
125 }
126 }
127#ifdef USE_HUE
128 ihue+=1;
129#endif
130
131 FastLED.show();
132 // delay(10);
133}
void setup()
void loop()
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
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
void fillnoise8()
Definition Noise.ino:97
#define MAX_DIMENSION
Definition Noise.ino:24
#define kMatrixSerpentineLayout
#define kMatrixHeight
#define kMatrixWidth
FL_OPTIMIZATION_LEVEL_O3_BEGIN fl::u16 XY(fl::u8 x, fl::u8 y) FL_LINK_WEAK
Definition blur.cpp.hpp:35
constexpr EOrder RGB
Definition eorder.h:17
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
unsigned char uint8_t
Definition s16x16x4.h:209