Skip to content

Instantly share code, notes, and snippets.

@jclement
Created January 26, 2016 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jclement/479830a0793edbd8fad8 to your computer and use it in GitHub Desktop.
Save jclement/479830a0793edbd8fad8 to your computer and use it in GitHub Desktop.
#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 5
struct pt {
byte r;
byte g;
byte b;
int p;
int dir;
int speed;
};
pt points[PT_COUNT];
void pt_init(pt *point) {
byte brightness = random(0,10) * 10;
point->r = brightness;
point->g = brightness;
point->b = brightness + random(0,10) * 10;;
point->p = LED_COUNT + random(0, 10);
point->dir = -1;
point->speed = random(1,5);
}
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) {
pt_init(point);
}
}
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()
{
// Ride the Rainbow Road
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