Skip to content

Instantly share code, notes, and snippets.

@phoenixperry
Last active August 29, 2015 14:17
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 phoenixperry/055fbbe723b6e29d640d to your computer and use it in GitHub Desktop.
Save phoenixperry/055fbbe723b6e29d640d to your computer and use it in GitHub Desktop.
/*
* This is a minimal example, see extra-examples.cpp for a version
* with more explantory documentation, example routines, how to
* hook up your pixels and all of the pixel types that are supported.
*
*/
#include "application.h"
//#include "spark_disable_wlan.h" // For faster local debugging only
#include "neopixel.h"
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 2
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
//currntly displaying color
uint32_t r= 255;
uint32_t g= 255;
uint32_t b= 255;
//variables for fading colors
uint32_t current_r = 255;
uint32_t current_g=255;
uint32_t current_b =255;
uint32_t target_r = 255;
uint32_t target_b = 255;
uint32_t target_g =255;
uint32_t col =255; //current color - this will get refactored later.
//start fade at 0%
float pct = 0;
//fucntions for calling from OF
int set_color(String command){
//for as long as we have pixels
if(command == "light_blue"){target_r=0; target_g=0; target_b=255;}
else if(command == "teal"){target_r=0; target_g=155; target_b=100;Serial.println("teal");}
else if(command=="pink"){target_r=200; target_g=0; target_b=10;}
else if(command=="grey"){target_r=255; target_g=0; target_b=0;}
else if(command=="orange"){target_r=255; target_g=255; target_b=0;}
else if(command=="yellow"){target_r=25; target_g=200; target_b=40;}
else if(command=="cream"){target_r=10; target_g=30; target_b=40;}
//violet is last!
else { target_r=255; target_g=0; target_b=255;}
for(int16_t i=0; i<strip.numPixels(); i++)
{
//serial.println("changingpixels");
//change each rgb value one at a time
for(int16_t i=0; i< 256; i++)
{
//divide by 255 to get closer and closer to 1
pct = i/255;
//fade from old color to new
r = (1-pct) * current_r + (pct) * target_r;
g = (1-pct) * current_b + (pct) * target_b;
b = (1-pct) * current_g + (pct) * target_g;
//transition the actual pixels
col = strip.Color(r,g,b);
strip.setPixelColor(i, col);
}
strip.show();
delay(1000);
}
//make sure the color we set the current color when we are done fading in
current_r = r;
current_g = b;
current_b = b;
return col;
}
void setup()
{
//ultimately I'll have an exposed function for each color to change the active color. right now only this one is stubbed in.
Spark.function("set_color", set_color);
//code required to start the strip up
strip.begin();
strip.show();
// Make sure your //serial Terminal app is closed before powering your Core
//serial.begin(9600);
// Now open your //serial Terminal, and hit any key to continue!
//while(!//serial.available()) SPARK_WLAN_Loop();
}
void loop()
{
for(int i=0; i< strip.numPixels()+1; i++)
{
//serial.println("got to else");
col = strip.Color(r,g,b);
strip.setPixelColor(i, col);
}
strip.show();
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment