Permalink
Browse files

some code cleanup

  • Loading branch information...
1 parent eeb820f commit f17cf66c8c83b2819d793dc55bcc3e33358d39f6 @neophob committed Nov 23, 2011
Showing with 22 additions and 12 deletions.
  1. +22 −12 examples/stars/stars.pde
View
34 examples/stars/stars.pde
@@ -41,9 +41,7 @@ void setup() {
for (int i=0; i < strip.numPixels(); i++) {
if (random(RND)==2) {
- stars[i].endCol = random(0xffffff);
- stars[i].pos = 1;
- stars[i].currentCol=0;
+ initStar(i);
} else {
stars[i].pos = 0;
}
@@ -57,19 +55,19 @@ void loop() {
uint8_t endR, endG, endB;
for (int i=0; i < strip.numPixels(); i++) {
- //start a new fader, maybe
+
+ // ====
+ // INIT
+ // ====
if (stars[i].pos == 0) {
if (random(RND)==2) {
-// stars[i].endCol = random(0xffffff);
- uint8_t rnd = random(192);
- uint8_t rnd2 = random(64);
- stars[i].endCol = Color(rnd+rnd2, rnd+rnd2, rnd2);
- stars[i].pos = 1;
- stars[i].currentCol=0;
+ initStar(i);
}
} else
- //fade in
+ // =======
+ // FADE IN
+ // =======
if (stars[i].pos == 1) {
//decrease color...
@@ -98,7 +96,9 @@ void loop() {
stars[i].currentCol = Color(currentR, currentG, currentB);
} else
- //fade out
+ // ========
+ // FADE OUT
+ // ========
if (stars[i].pos == 2) {
//decrease color...
uint32_t ccol = stars[i].currentCol;
@@ -119,13 +119,23 @@ void loop() {
}
}
+ //update color
strip.setPixelColor(i, stars[i].currentCol);
}
strip.show();
delay(DELAY);
}
+//init new star
+void initStar(int i) {
+ uint8_t rnd = random(192);
+ uint8_t rnd2 = random(64);
+ stars[i].endCol = Color(rnd+rnd2, rnd+rnd2, rnd2);
+ stars[i].pos = 1;
+ stars[i].currentCol=0;
+}
+
// Create a 24 bit color value from R,G,B
uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {

0 comments on commit f17cf66

Please sign in to comment.