Skip to content

Instantly share code, notes, and snippets.

@alan707
Created November 9, 2016 16:06
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 alan707/c774b734aa1f55ec66791ba6d094ec21 to your computer and use it in GitHub Desktop.
Save alan707/c774b734aa1f55ec66791ba6d094ec21 to your computer and use it in GitHub Desktop.
/* ======================= includes ================================= */
#include "blynk/blynk.h"
#include "clickButton/clickButton.h"
#include "application.h"
#include "neopixel/neopixel.h" // use for Build IDE
// #include "neopixel.h" // use for local build
/* ======================= variables =============================== */
char auth[] = "7be57b2b0f0b4df0bd93d9bbd9f86e02";
// uint32_t Wheel(byte WheelPos);
// uint8_t red(uint32_t c);
// uint8_t green(uint32_t c);
// uint8_t blue(uint32_t c);
void colorWipe(uint32_t c, uint8_t wait);
void pulseWhite(uint8_t wait);
void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops);
void whiteOverRainbow(uint8_t wait, uint8_t whiteSpeed, uint8_t whiteLength);
void fullWhite();
void rainbowCycle(uint8_t wait);
void rainbow(uint8_t wait);
// the Button
const int buttonPin1 = 3;
ClickButton button1(buttonPin1, HIGH, CLICKBTN_PULLUP);
// Button results
int function = 0;
int state = 0;
/* ======================= rgbw-strandtest.cpp ====================== */
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
// #define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE SK6812RGBW
#define BRIGHTNESS 255 // 0 - 255
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(PIXEL_COUNT, D2, PIXEL_TYPE);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(PIXEL_COUNT, D1, PIXEL_TYPE);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(PIXEL_COUNT, D0, PIXEL_TYPE);
int gamma[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
void setup() {
pinMode(D3, INPUT_PULLDOWN);
// Setup button timers (all in milliseconds / ms)
// (These are default if not set, but changeable for convenience)
button1.debounceTime = 20; // Debounce timer in ms
button1.multiclickTime = 250; // Time limit for multi clicks
button1.longClickTime = 300; // time until "held-down clicks" register
strip1.setBrightness(BRIGHTNESS);
strip1.begin();
strip1.show(); // Initialize all pixels to 'off'
strip2.setBrightness(BRIGHTNESS);
strip2.begin();
strip2.show(); // Initialize all pixels to 'off'
strip3.setBrightness(BRIGHTNESS);
strip3.begin();
strip3.show(); // Initialize all pixels to 'off'
Blynk.begin(auth);
// pinMode(button_LED, OUTPUT); // sets pin as output
// pinMode(button, INPUT_PULLDOWN);
}
BLYNK_WRITE(V0) {
if (param.asInt() == 1) { // On button down...
// Tweeting!
// Note:
// We allow 1 tweet per minute for now.
// Twitter doesn't allow identical subsequent messages.
fullWhite();
}
if (param.asInt() == 0) { // On button down...
// Tweeting!
// Note:
// We allow 1 tweet per minute for now.
// Twitter doesn't allow identical subsequent messages.
fullOff();
}
}
void loop() {
Blynk.run();
state = digitalRead(D0);
// delay(1000);
// Some example procedures showing how to display to the pixels:
// Do not run more than 15 seconds of these, or the b/g tasks
// will be blocked.
// --------------------------------------------------------------
// colorWipe(strip1.Color(255, 0, 0), 50); // Red
// colorWipe(strip.Color(0, 255, 0), 50); // Green
// colorWipe(strip.Color(0, 0, 255), 50); // Blue
// colorWipe(strip.Color(0, 0, 0, 255), 50); // White
// whiteOverRainbow(20,75,5);
// Update button state
button1.Update();
if(button1.clicks != 0) function = button1.clicks;
if(function == 1 ) {
// if (state = LOW) {
fullWhite();
// breathAll();
// Serial.println("button on");
// delay(1000);
// state = HIGH;
// }
}
if(function == -1 ) {
// if (state = HIGH) {
fullOff();
// delay(1000);
// Serial.println("button off");
// delay(300);
// state = LOW;
}
// }
if (Particle.connected() == false) {
Particle.connect();
}
}
BLYNK_WRITE(V3)
{
int shift = param.asInt();
for (int i = 0; i < strip1.numPixels(); i++)
{
strip1.setPixelColor(i, Wheel(shift & 255));
// OR: strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + shift) & 255));
}
strip1.show();
for (int i = 0; i < strip2.numPixels(); i++)
{
strip2.setPixelColor(i, Wheel(shift & 255));
// OR: strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + shift) & 255));
}
strip2.show();
for (int i = 0; i < strip3.numPixels(); i++)
{
strip3.setPixelColor(i, Wheel(shift & 255));
// OR: strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + shift) & 255));
}
strip3.show();
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip1.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
return strip2.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
return strip3.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip1.Color(255 - WheelPos * 3, 0, WheelPos * 3);
return strip2.Color(255 - WheelPos * 3, 0, WheelPos * 3);
return strip3.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip1.Color(0, WheelPos * 3, 255 - WheelPos * 3);
return strip2.Color(0, WheelPos * 3, 255 - WheelPos * 3);
return strip3.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void fullWhite() {
for(uint16_t i=0; i<strip1.numPixels(); i++) {
strip1.setPixelColor(i, strip1.Color(0,0,0, 255 ) );
}
strip1.show();
for(uint16_t i=0; i<strip2.numPixels(); i++) {
strip2.setPixelColor(i, strip2.Color(0,0,0, 255 ) );
}
strip2.show();
for(uint16_t i=0; i<strip3.numPixels(); i++) {
strip3.setPixelColor(i, strip3.Color(0,0,0, 255 ) );
}
strip3.show();
}
void fullOff() {
for(uint16_t i=0; i<strip1.numPixels(); i++) {
strip1.setPixelColor(i, strip1.Color(0,0,0, 0) );
}
strip1.show();
for(uint16_t i=0; i<strip2.numPixels(); i++) {
strip2.setPixelColor(i, strip2.Color(0,0,0, 0) );
}
strip2.show();
for(uint16_t i=0; i<strip3.numPixels(); i++) {
strip3.setPixelColor(i, strip3.Color(0,0,0, 0) );
}
strip3.show();
}
// // Slightly different, this makes the rainbow equally distributed throughout
// void rainbowCycle(uint8_t wait) {
// uint16_t i, j;
// for(j=0; j<256 * 5; j++) { // 5 cycles of all colors on wheel
// for(i=0; i< strip1.numPixels(); i++) {
// strip1.setPixelColor(i, Wheel(((i * 256 / strip1.numPixels()) + j) & 255));
// }
// strip1.show();
// delay(wait);
// }
// }
// void rainbow(uint8_t wait) {
// uint16_t i, j;
// for(j=0; j<256; j++) {
// for(i=0; i<strip1.numPixels(); i++) {
// strip1.setPixelColor(i, Wheel((i+j) & 255));
// }
// strip1.show();
// delay(wait);
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment