Created
January 26, 2016 03:09
-
-
Save jclement/19641d3a8f99a0108638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Arduino.h" | |
#include <Adafruit_NeoPixel.h> | |
#define PIN 4 | |
#define LED_COUNT 60 | |
// Create an instance of the Adafruit_NeoPixel class called "leds". | |
// That'll be what we refer to from here on... | |
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800); | |
#define PT_COUNT 10 | |
struct pt { | |
byte r; | |
byte g; | |
byte b; | |
int p; | |
int dir; | |
int speed; | |
}; | |
pt points[PT_COUNT]; | |
void pt_init(pt *point) { | |
point->r = random(0,100); | |
point->g = random(0,100); | |
point->b = random(0,100); | |
point->p = random(0, LED_COUNT-1); | |
point->dir = random(0,1); | |
if (point->dir == 0) point->dir = -1; | |
point->speed = random(1,3); | |
} | |
void pt_update(pt *point) { | |
leds.setPixelColor(point->p, point->r, point->g, point->b); | |
point->p += point->dir * point->speed; | |
if (point->p < 0 || point->p > LED_COUNT-1) { | |
point->dir *= -1; | |
point->p += point->dir * point->speed; | |
} | |
} | |
void setup() | |
{ | |
leds.begin(); // Call this to start up the LED strip. | |
randomSeed(analogRead(0)); | |
for(int i=0; i< PT_COUNT; i++) { | |
pt_init(&points[i]); | |
} | |
} | |
void loop() | |
{ | |
for (int i=0; i<=LED_COUNT-1; i++) { | |
leds.setPixelColor(i, 0, 0, 0); | |
} | |
for (int i=0; i<PT_COUNT; i++) { | |
pt_update(&points[i]); | |
} | |
leds.show(); | |
delay(40); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment