Guest User

Untitled

a guest
Dec 22nd, 2015
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. // This #include statement was automatically added by the Particle IDE.
  2. #include "FastLED/FastLED.h"
  3. FASTLED_USING_NAMESPACE;
  4.  
  5. const uint8_t kMatrixWidth = 12;
  6. const uint8_t kMatrixHeight = 23;
  7.  
  8. #define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
  9. #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
  10.  
  11. const bool    kMatrixSerpentineLayout = true;
  12.  
  13. uint16_t XY( uint8_t x, uint8_t y)
  14. {
  15.   uint16_t i;
  16.  
  17.   if( kMatrixSerpentineLayout == false) {
  18.     i = (y * kMatrixWidth) + x;
  19.   }
  20.  
  21.   if( kMatrixSerpentineLayout == true) {
  22.     if( y & 0x01) {
  23.       uint8_t reverseX = (kMatrixWidth - 1) - x;
  24.       i = (y * kMatrixWidth) + reverseX;
  25.     } else {
  26.       i = (y * kMatrixWidth) + x;
  27.     }
  28.   }
  29.  
  30.   return i;
  31. }
  32.  
  33. CRGB leds[kMatrixWidth * kMatrixHeight];
  34.  
  35. static uint16_t x;
  36. static uint16_t y;
  37. static uint16_t z;
  38.  
  39. uint16_t speed = 3;
  40. uint16_t scale = 311;
  41. uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
  42.  
  43. void setup() {
  44.  
  45.   FastLED.addLeds<WS2812B,23,RGB>(leds,NUM_LEDS,0);
  46.   FastLED.setBrightness(20);
  47.  
  48.   x = random16();
  49.   y = random16();
  50.   z = random16();
  51. }
  52.  
  53. void fillnoise8() {
  54.   for(int i = 0; i < MAX_DIMENSION; i++) {
  55.     int ioffset = scale * i;
  56.     for(int j = 0; j < MAX_DIMENSION; j++) {
  57.       int joffset = scale * j;
  58.       noise[i][j] = inoise8(x + ioffset,y + joffset,z);
  59.     }
  60.   }
  61.   z += speed;
  62. }
  63.  
  64. void loop() {
  65.   static uint8_t ihue=0;
  66.   fillnoise8();
  67.   for(int i = 0; i < kMatrixWidth; i++) {
  68.     for(int j = 0; j < kMatrixHeight; j++) {
  69.       leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
  70.     }
  71.   }
  72.   ihue+=1;
  73.  
  74.   LEDS.show();
  75.   delay(10);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment