Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Digital Rain implementation for fibonacci 256
- //fastled fibonacci 256 leds demo
- //Yaroslaw Turbin 28.01.2020
- //https://vk.com/ldirko
- //https://www.reddit.com/user/ldirko/
- //https://twitter.com/ldir_ko
- //https://wokwi.com/arduino/projects/288948170884383245
- #include "FastLED.h"
- // Matrix size
- #define NUM_ROWS 20
- #define NUM_COLS 20
- // LEDs pin
- #define DATA_PIN 3
- // LED brightness
- #define BRIGHTNESS 255
- #define NUM_LEDS NUM_ROWS * NUM_COLS
- // Define the array of leds
- CRGB leds[257];
- byte rain[NUM_LEDS];
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- raininit();
- }
- void loop() {
- EVERY_N_MILLISECONDS(80) {
- updaterain();
- }
- EVERY_N_MILLISECONDS(15) {
- changepattern();
- }
- FastLED.show();
- } //loop
- void changepattern () {
- int rand1 = random16 (NUM_LEDS);
- int rand2 = random16 (NUM_LEDS);
- if (rain[rand1] && !rain[rand2]) {rain[rand1] = 0; rain[rand2] = 1;}
- } //changepattern
- void raininit() { //init array of dots. run once
- for (int i = 0; i < NUM_LEDS; i++) rain[i] = !random8(15)? 1:0;
- } //raininit
- void updaterain() {
- static const CRGB hue = CHSV(100,255,255);
- static uint16_t speed;
- for (byte j = 0; j < NUM_ROWS; j++) {
- uint16_t index = (j - speed) % (NUM_ROWS) * NUM_COLS;
- for (byte i = 0; i < NUM_COLS; i++) {
- uint16_t ledsindex = XY(i, j);
- leds[ledsindex].fadeToBlackBy(40);
- if (rain[index + i] & ledsindex!=256) leds[ledsindex]=hue;
- }}
- speed++;
- }
- uint16_t XY(byte x, byte y) {
- static const uint16_t FibonPlanarTable[] PROGMEM ={
- 256, 256, 256, 256, 256, 256, 256, 256, 247, 213, 234, 255, 256, 256, 256, 256, 256, 256, 256, 256,
- 256, 256, 256, 256, 256, 239, 205, 226, 192, 256, 179, 200, 221, 242, 256, 256, 256, 256, 256, 256,
- 256, 256, 256, 256, 218, 184, 256, 171, 137, 158, 124, 145, 166, 187, 208, 229, 256, 256, 256, 256,
- 256, 256, 256, 252, 197, 163, 150, 116, 256, 103, 256, 111, 132, 153, 174, 195, 250, 256, 256, 256,
- 256, 256, 231, 176, 142, 256, 129, 95, 82, 69, 90, 77, 98, 119, 140, 161, 216, 237, 256, 256,
- 256, 244, 210, 155, 121, 108, 74, 61, 48, 256, 56, 256, 64, 85, 106, 127, 182, 203, 256, 256,
- 256, 223, 189, 134, 100, 87, 53, 40, 27, 35, 256, 43, 51, 72, 93, 114, 148, 169, 224, 256,
- 256, 202, 168, 113, 79, 66, 256, 32, 19, 14, 22, 30, 38, 59, 80, 256, 135, 256, 190, 245,
- 236, 181, 147, 92, 256, 58, 45, 256, 11, 6, 9, 17, 25, 46, 256, 101, 256, 156, 256, 211,
- 215, 160, 126, 256, 71, 256, 37, 24, 3, 256, 1, 4, 12, 33, 67, 256, 122, 256, 177, 232,
- 249, 194, 139, 105, 256, 50, 29, 16, 8, 0, 2, 7, 20, 41, 54, 88, 256, 143, 198, 253,
- 228, 173, 256, 118, 84, 63, 42, 21, 13, 5, 256, 15, 28, 256, 62, 75, 109, 164, 219, 256,
- 256, 207, 152, 256, 97, 76, 55, 34, 26, 18, 10, 23, 36, 49, 83, 96, 130, 185, 240, 256,
- 256, 241, 186, 131, 110, 89, 68, 47, 256, 39, 31, 44, 57, 70, 104, 117, 151, 206, 256, 256,
- 256, 256, 220, 165, 144, 256, 256, 256, 60, 256, 52, 65, 78, 91, 125, 138, 172, 227, 256, 256,
- 256, 256, 254, 199, 178, 123, 102, 81, 94, 73, 86, 256, 99, 112, 146, 159, 193, 248, 256, 256,
- 256, 256, 256, 233, 212, 157, 136, 115, 128, 107, 256, 120, 133, 167, 256, 180, 214, 256, 256, 256,
- 256, 256, 256, 256, 256, 191, 170, 149, 256, 162, 141, 154, 188, 256, 201, 235, 256, 256, 256, 256,
- 256, 256, 256, 256, 256, 246, 225, 204, 183, 196, 175, 209, 256, 222, 256, 256, 256, 256, 256, 256,
- 256, 256, 256, 256, 256, 256, 256, 238, 217, 251, 230, 256, 243, 256, 256, 256, 256, 256, 256, 256 };
- uint16_t ledsindex = pgm_read_word (FibonPlanarTable+y*NUM_COLS+x);
- return (ledsindex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement