We ditched the regular LEDs for a much more sophisticated RGB LED Neopixel. Our assignment was to create a narrative using only one Neopixel light. I decided to depict a journey through the solar system that represented the sun and all 8 planets (sorry Pluto, I’ll never forget) working from the center outward. I’m still having a hard time condensing my code into clean and organized thoughts. We worked through another student’s project in class to get a better understanding of controlling time, but I seriously feel lost with this concept. The example code was a loop with randomization, not a straight path through time which is what I need to accomplish my planet animation. I took the same approach to timing the animation as my previous project because this is the only way I know how to make it work. Hopefully I can get a better grasp in the next class before we start working with LED arrays.

Well I had an animation I was happy with, but I screwed up my code when consolidating it, so the animation didn’t even work when I presented it. Here is the code:

#include <Adafruit_NeoPixel.h> //Connect to NeoPixel library.

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, 6, NEO_GRB + NEO_KHZ800);

int r = 1;
int g = 1;
int b = 1;

bool rUp = 1; //On or off. 1 = on.
bool gUp = 1; //On or off. 1 = on.
bool bUp = 1; //On or off. 1 = on.

unsigned long currentTime = 0;
unsigned long lastTime = 0;
unsigned long counter = 0;
int timer1 = 2;
int timer2 = 10;
int timer3 = 10;
int timer4 = 15;
int timer5 = 15;
int timer6 = 10;
int timer7 = 15;
int timer8 = 10;
int timer9 = 10;

unsigned long scene1 = 5000;
unsigned long scene2 = 10000;
unsigned long scene3 = 15000;
unsigned long scene4 = 20000;
unsigned long scene5 = 25000;
unsigned long scene6 = 30000;
unsigned long scene7 = 35000;
unsigned long scene8 = 40000;
unsigned long scene9 = 45000;

void setup() {
pixels.begin();

}

void loop() {
currentTime = millis();

if (currentTime < scene1) {
fader(2, 254, 170, 80, 40, 2, 1); //Sun
}

if (currentTime > scene1 && currentTime <= scene2) {
fader(10, 65, 64, 65, 64, 65, 64); //Mercury
}

if (currentTime > scene2 && currentTime <= scene3) {
fader(10, 254, 250, 254, 160, 2, 1); //Venus
}

if (currentTime > scene3 && currentTime <= scene4) {
fader2(15, 2, 1, 125, 110, 254, 1); //Earth
}

if (currentTime > scene4 && currentTime <= scene5) {
fader(15, 254, 120, 40, 1, 25, 15); //Mars
}

if (currentTime > scene5 && currentTime <= scene6) {
fader(10, 180, 165, 140, 1, 25, 15); //Jupiter
}

if (currentTime > scene6 && currentTime <= scene7) {
fader(10, 115, 90, 59, 57, 17, 15); //Saturn
}

if (currentTime > scene7 && currentTime <= scene8) {
fader(10, 45, 35, 204, 180, 220, 212); //Uranus
}

if (currentTime > scene8 && currentTime <= scene9) {
fader(15, 165, 140, 30, 1, 240, 220); //Neptune
}
}

void fader(int timer,int redMax,int redMin, int greenMax, int greenMin, int blueMax, int blueMin) { //Sun

if (currentTime – lastTime > timer) {

if (rUp) {
r++;
} else r–;

if (gUp) {
g++;
} else g–;
if (bUp) {
b++;
} else b–;

if (r > redMax) rUp = 0;
if (r < redMin) rUp = 1;
if (g > greenMax) gUp = 0;
if (g < greenMin) gUp = 1;
if (b > blueMax) bUp = 0;
if (b < blueMin) bUp = 1;

pixels.setPixelColor(0, pixels.Color(r, g, b));
pixels.show();
lastTime = currentTime;
}
}

void fader2(int timer,int redMax,int redMin, int greenMax, int greenMin, int blueMax, int blueMin) { //Earth

if (currentTime – lastTime > timer) {

if (rUp) {
r++;
} else r–;

if (gUp) {
g++;
} else g–;
if (bUp) {
b = (cos(currentTime / 500.0) + 1.0) * 128.0;
} else b = (sin(currentTime / 500.0) – 1.0) * 128.0;

if (redMax > 2) rUp = 0;
if (redMin < 1) rUp = 1;
if (greenMax > 125) gUp = 0;
if (greenMin < 110) gUp = 1;
if (blueMax > 254) bUp = 0;
if (blueMin < 1) bUp = 1;

pixels.setPixelColor(0, pixels.Color(r, g, b));
pixels.show();
lastTime = currentTime;
}
}

I’m going back to Shiffman’s Function tutorials, because I just can’t seem to get this stuff to stick in my brain. I’m having the same challenge with programming as I did with advanced math, in one ear and out the other, especially when it comes to multiple levels of abstraction. In the end, I think I may be more successful in my future multimedia projects using a visual programming aid like Max. I feel like it’s important for me to understand programming at the deepest level I can handle.

Meanwhile, I’m checking out some different project examples to spark some creative ideas for what I’m guessing will be a more elaborate project assignment involving our use of LEDs. For my own entertainment, I’d love to get a strip of neopixels attached to me Parrot 2.0 drone, but these glasses are pretty badass too.