Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #define PIN 2
- #define Pixels 24
- #define BG 1
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);
- int color;
- int center = 0;
- int step = -1;
- int maxSteps = 16;
- float fadeRate = 0.6;
- int diff;
- //background color
- uint32_t currentBg = random(256);
- uint32_t nextBg = currentBg;
- void setup() {
- strip.begin();
- strip.show(); // Initialize all pixels to 'off'
- }
- void loop () {
- ripple();
- }
- void ripple() {
- if (BG){
- if (currentBg == nextBg) {
- nextBg = random(256);
- }
- else if (nextBg > currentBg) {
- currentBg++;
- } else {
- currentBg--;
- }
- for(uint16_t l = 0; l < Pixels; l++) {
- strip.setPixelColor(l, Wheel(currentBg, 0.1));
- }
- } else {
- for(uint16_t l = 0; l < Pixels; l++) {
- strip.setPixelColor(l, 0, 0, 0);
- }
- }
- if (step == -1) {
- center = random(Pixels);
- color = random(256);
- step = 0;
- }
- if (step == 0) {
- strip.setPixelColor(center, Wheel(color, 1));
- step ++;
- }
- else {
- if (step < maxSteps) {
- strip.setPixelColor(wrap(center + step), Wheel(color, pow(fadeRate, step)));
- strip.setPixelColor(wrap(center - step), Wheel(color, pow(fadeRate, step)));
- if (step > 3) {
- strip.setPixelColor(wrap(center + step - 3), Wheel(color, pow(fadeRate, step - 2)));
- strip.setPixelColor(wrap(center - step + 3), Wheel(color, pow(fadeRate, step - 2)));
- }
- step ++;
- }
- else {
- step = -1;
- }
- }
- strip.show();
- delay(50);
- }
- int wrap(int step) {
- if(step < 0) return Pixels + step;
- if(step > Pixels - 1) return step - Pixels;
- return step;
- }
- // Input a value 0 to 255 to get a color value.
- // The colours are a transition r - g - b - back to r.
- uint32_t Wheel(byte WheelPos, float opacity) {
- if(WheelPos < 85) {
- return strip.Color((WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity, 0);
- }
- else if(WheelPos < 170) {
- WheelPos -= 85;
- return strip.Color((255 - WheelPos * 3) * opacity, 0, (WheelPos * 3) * opacity);
- }
- else {
- WheelPos -= 170;
- return strip.Color(0, (WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment