/* Multicolored Plasma for the Arduino Micro-Controller and NeoPixel Shield Copyright (C) 2019 John Ericksen This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. */ #include // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_RGB Pixels are wired for RGB bitstream // NEO_GRB Pixels are wired for GRB bitstream // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) const int ROWS = 5; const int COLS = 8; const int NUM_LEDS = ROWS * COLS; const int LED_PIN = 6; const float phaseIncrement = 0.03; // Controls the speed of the moving points. Higher == faster. I like 0.08 . const float colorStretch = 0.3; // Higher numbers will produce tighter color bands. I like 0.11 . Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); // Convenient 2D point structure struct Point { float x; float y; }; void setup() { strip.begin(); strip.show(); // Initialize all pixels to 'off' } float phase = 0.0; // This function is called every frame. void loop() { phase += phaseIncrement; // The two points move along Lissajious curves, see: http://en.wikipedia.org/wiki/Lissajous_curve // We want values that fit the LED grid: x values between 0..13, y values between 0..8 . // The sin() function returns values in the range of -1.0..1.0, so scale these to our desired ranges. // The phase value is multiplied by various constants; I chose these semi-randomly, to produce a nice motion. Point p1 = { (sin(phase*1.000)+1.0) * 4.5, (sin(phase*1.310)+1.0) * 4.0 }; Point p2 = { (sin(phase*1.770)+1.0) * 4.5, (sin(phase*2.865)+1.0) * 4.0 }; Point p3 = { (sin(phase*0.250)+1.0) * 4.5, (sin(phase*0.750)+1.0) * 4.0 }; byte row, col; // For each row... for( row=0; row