#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 48
short rl1[24] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
short rr1[24] = { 24, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25 };
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
pixels.setBrightness(255);
Serial.begin(9600);
}
class Goo {
unsigned short pos;
unsigned short ppos;
float fi;
float speed;
int32_t color;
boolean d;
boolean dset;
public:
Goo(int tempPos, float tempSpeed, int32_t tempColor) {
pos = tempPos;
fi = tempPos;
speed = tempSpeed;
color = tempColor;
}
void display() {
pixels.setPixelColor(ppos, pixels.Color(0, 0, 0)); // erase or subtract last position
pixels.setPixelColor(pos, addC(pos, color)); // draw new pos
ppos = pos;
}
void move() {
int i;
fi += speed;
if (fi > 32767) fi -= 32760;
i = short(int(fi) % 24);
if (i == 0 && !dset) {
dset = true;
if (millis() % 2) {
d = true;
} else {
d = false;
}
}
if (i == 12) dset = false;
if (d) pos = rl1[i];
else pos = rr1[i];
}
};
Goo goo1(0, 0.198, pixels.Color(255, 0, 0));
Goo goo2(0, 0.2, pixels.Color(0, 255, 0));
Goo goo3(0, 0.202, pixels.Color(0, 0, 255));
// Goo goo1(0, 0.149, pixels.Color(200, 0, 0));
// Goo goo2(0, 0.15, pixels.Color(0, 200, 0));
// Goo goo3(0, 0.151, pixels.Color(0, 0, 255));
void loop() {
goo1.move();
goo2.move();
goo3.move();
goo1.display();
goo2.display();
goo3.display();
pixels.show();
delay(5);
}
uint32_t addC( int pixel, uint32_t color)
{
uint32_t currentColor = pixels.getPixelColor(pixel);
// Get the RGB components of the current color
uint8_t r1 = (currentColor >> 16) & 0xff;
uint8_t g1 = (currentColor >> 8) & 0xff;
uint8_t b1 = (currentColor >> 0) & 0xff;
// Get the RGB components of the new color
uint8_t r2 = (color >> 16) & 0xff;
uint8_t g2 = (color >> 8) & 0xff;
uint8_t b2 = (color >> 0) & 0xff;
// Mix the RGB components using the subtractive color model
uint8_t r = r1 + r2 > 255 ? 255 : r1 + r2;
uint8_t g = g1 + g2 > 255 ? 255 : g1 + g2;
uint8_t b = b1 + b2 > 255 ? 255 : b1 + b2;
// return the mixed color of the NeoPixel
return pixels.Color(r, g, b);
}