Skip to content

Instantly share code, notes, and snippets.

@jsonpoindexter
Last active August 29, 2015 14:22
Show Gist options
  • Save jsonpoindexter/caba8570b78b78d2c146 to your computer and use it in GitHub Desktop.
Save jsonpoindexter/caba8570b78b78d2c146 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 3
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 128
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS , PIN, NEO_GRB + NEO_KHZ800);;
void setup(void)
{
Serial.begin(115200);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
delay(2000);
}
byte Start = 0; // start byte is dec 0
byte Stop = 1; // stop byte is dec 1
int maxLoops = 100;
int postDelay = 100; //delay after the Stop byte gets sent in order to give Processing time to be ready for next Start signal
void loop(void)
{
Serial.write(Start);
for(int loopCount = 0; loopCount < 100; loopCount++){
for(int i = 0; i < NUMPIXELS; i++){
strip.setPixelColor(i, color(map(i,0,NUMPIXELS,1,384),1));
}
strip.show();
}
Serial.write(Stop);
delay(postDelay);
}
// Color 1 from 384; brightness 0.0 to 1.0.
uint32_t color(uint16_t color, float brightness) {
byte r, g, b;
int range = color / 128;
switch (range) {
case 0: // Red to Yellow (1 to 128)
r = 127 - color % 128;
g = color % 128;
b = 0;
break;
case 1: // Yellow to Teal (129 to 256)
r = 0;
g = 127 - color % 128;
b = color % 128;
break;
case 2: // Teal to Purple (257 to 384)
r = color % 128;
g = 0;
b = 127 - color % 128;
break;
}
r *= brightness;
g *= brightness;
b *= brightness;
return strip.Color(r, g, b);
}
#include <FastLED.h>
#define LED_PIN 3
#define NUM_LEDS 128
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
#define WAIT_FOR_KEYBOARD 0
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
void setup() {
Serial.begin(115200);
if (WAIT_FOR_KEYBOARD) {
// Wait for serial to initalize.
while (!Serial) { }
Serial.println("Strike any key to start...");
// Wait for the next keystroke.
while (!Serial.available()) { }
// Clear the serial buffer.
Serial.read();
}
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
currentPalette = RainbowColors_p;
currentBlending = BLEND;
}
static uint8_t startIndex = 0;
byte Start = 0; // start byte is dec 0
byte Stop = 1; // stop byte is dec 1
int maxLoops = 100;
int postDelay = 100; //delay after the Stop byte gets sent in order to give Processing time to be ready for next Start signal
void loop()
{
Serial.write(Start);
for(int loopCount = 0; loopCount < 100; loopCount++){
FillLEDsFromPaletteColors(startIndex);
FastLED.show();
}
Serial.write(Stop);
delay(postDelay);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for( int i = 0; i < NUM_LEDS; i++) {
colorIndex = map(i,0,NUM_LEDS,0,255);
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment