#if defined(__AVR_ATtinyxy4__)
const uint8_t kMatrixWidth = 8;
const uint8_t kMatrixHeight = 8;
#else
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
#endif
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
const bool kMatrixSerpentineLayout = true;
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
}
if( kMatrixSerpentineLayout == true) {
if( y & 0x01) {
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
i = (y * kMatrixWidth) + x;
}
}
return i;
}
CRGB leds[kMatrixWidth * kMatrixHeight];
static uint16_t x;
static uint16_t y;
static uint16_t z;
uint16_t speed = 20;
uint16_t scale = 311;
uint16_t noise[MAX_DIMENSION][MAX_DIMENSION];
void setup() {
delay(3000);
}
void fillnoise8() {
for(int i = 0; i < MAX_DIMENSION; i++) {
int ioffset = scale * i;
for(int j = 0; j < MAX_DIMENSION; j++) {
int joffset = scale * j;
noise[i][j] =
inoise8(x + ioffset,y + joffset,z);
}
}
z += speed;
}
void loop() {
static uint8_t ihue=0;
fillnoise8();
for(int i = 0; i < kMatrixWidth; i++) {
for(int j = 0; j < kMatrixHeight; j++) {
leds[XY(i,j)] =
CHSV(noise[j][i],255,noise[i][j]);
}
}
ihue+=1;
}
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
uint8_t inoise8(uint16_t x, uint16_t y, uint16_t z)
8-Bit, fixed point implementation of Perlin's noise.
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Representation of an RGB pixel (Red, Green, Blue)