FastLED 3.10.8
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_ATmega8__) || defined(__AVR_ATmega8A__) || \
16 defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny88__) || \
17 defined(__AVR_ATtiny204__) || defined(__AVR_ATtiny404__)
18// A 16x16 framebuffer alone uses 768 B, more than these boards can spare.
19const uint8_t kMatrixWidth = 4;
20const uint8_t kMatrixHeight = 4;
21#elif defined(__AVR_ATtinyxy4__)
22// Small matrix for this memory constrained device.
23const uint8_t kMatrixWidth = 8;
24const uint8_t kMatrixHeight = 8;
25#else
26const uint8_t kMatrixWidth = 16;
27const uint8_t kMatrixHeight = 16;
28#endif
29
30#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
31#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
32
33// Param for different pixel layouts
34const bool kMatrixSerpentineLayout = true;
35
36
37uint16_t XY( uint8_t x, uint8_t y)
38{
39 uint16_t i;
40
41 if( kMatrixSerpentineLayout == false) {
42 i = (y * kMatrixWidth) + x;
43 }
44
45 if( kMatrixSerpentineLayout == true) {
46 if( y & 0x01) {
47 // Odd rows run backwards
48 uint8_t reverseX = (kMatrixWidth - 1) - x;
49 i = (y * kMatrixWidth) + reverseX;
50 } else {
51 // Even rows run forwards
52 i = (y * kMatrixWidth) + x;
53 }
54 }
55
56 return i;
57}
58
59// The leds
61
62// The 32bit version of our coordinates
63static uint16_t x;
64static uint16_t y;
65static uint16_t z;
66
67// We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
68// use the z-axis for "time". speed determines how fast time moves forward. Try
69// 1 for a very slow moving effect, or 60 for something that ends up looking like
70// water.
71// uint16_t speed = 1; // almost looks like a painting, moves very slowly
72uint16_t speed = 20; // a nice starting speed, mixes well with a scale of 100
73// uint16_t speed = 33;
74// uint16_t speed = 100; // wicked fast!
75
76// Scale determines how far apart the pixels in our noise matrix are. Try
77// changing these values around to see how it affects the motion of the display. The
78// higher the value of scale, the more "zoomed out" the noise iwll be. A value
79// of 1 will be so zoomed in, you'll mostly see solid colors.
80
81// uint16_t scale = 1; // mostly just solid colors
82// uint16_t scale = 4011; // very zoomed out and shimmery
83uint16_t scale = 311;
84
85// This is the array that we keep our computed noise values in
87
88void setup() {
89 // uncomment the following lines if you want to see FPS count information
90 // Serial.begin(38400);
91 // Serial.println("resetting!");
92 delay(3000);
93 FastLED.addLeds<WS2811,2,RGB>(leds,NUM_LEDS);
94 FastLED.setBrightness(96);
95
96 // Initialize our coordinates to some random values
97 x = random16();
98 y = random16();
99 z = random16();
100}
101
102// Fill the x/y array of 8-bit noise values using the inoise8 function.
104 for(int i = 0; i < MAX_DIMENSION; i++) {
105 int ioffset = scale * i;
106 for(int j = 0; j < MAX_DIMENSION; j++) {
107 int joffset = scale * j;
108 noise[i][j] = inoise8(x + ioffset,y + joffset,z);
109 }
110 }
111 z += speed;
112}
113
114
115void loop() {
116#ifdef USE_HUE
117 static uint8_t ihue=0;
118#endif
119 fillnoise8();
120 for(int i = 0; i < kMatrixWidth; i++) {
121 for(int j = 0; j < kMatrixHeight; j++) {
122 // We use the value at the (i,j) coordinate in the noise
123 // array for our brightness, and the flipped value from (j,i)
124 // for our pixel's hue.
125#ifdef USE_HUE
126 // Slowly cycling base hue plus noise-derived offset
127 leds[XY(i,j)] = CHSV(ihue + (noise[j][i]>>2),255,noise[i][j]);
128#else
129 leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
130#endif
131 }
132 }
133#ifdef USE_HUE
134 ihue+=1;
135#endif
136
137 FastLED.show();
138 // delay(10);
139}
CRGB leds[1]
void setup()
void loop()
#define 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
uint8_t XY(uint8_t x, uint8_t y)
Definition Fire2023.h:219
fl::UISlider scale("Scale", 4,.1, 4,.1)
uint16_t speed
Definition Noise.ino:72
void fillnoise8()
Definition Noise.ino:103
#define MAX_DIMENSION
Definition Noise.ino:30
#define kMatrixSerpentineLayout
#define kMatrixHeight
#define kMatrixWidth
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) FL_NO_EXCEPT
LIB8STATIC fl::u16 random16() FL_NO_EXCEPT
Generate a 16-bit random number.
Definition random8.h:63
unsigned char uint8_t
Definition s16x16x4.h:209