Skip to content

Instantly share code, notes, and snippets.

@pipoblak
Created May 30, 2017 14:57
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 pipoblak/9e164e86242728e14f72500d2de9eeb4 to your computer and use it in GitHub Desktop.
Save pipoblak/9e164e86242728e14f72500d2de9eeb4 to your computer and use it in GitHub Desktop.
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
#define FASTLED_ALLOW_INTERRUPTS 0
#include "FastLED.h"
#include <Arduino.h>
#include <Thread.h>
#include <ThreadController.h>
//THREADS
ThreadController controll = ThreadController();
Thread threadRead = Thread();
Thread threadLight = Thread();
//SETTING STRIPS
#define PIN 2
#define NUM_LEDS 300
#define PIN2 1
#define NUM_LEDS2 300
#define PIN3 5
#define NUM_LEDS3 0
//ACTIVE STRIPS
boolean isActiveStrip1=true;
boolean isActiveStrip2=true;
boolean isActiveStrip3=false;
//CREATING STRIPS
CRGB strip1[NUM_LEDS];
CRGB strip2[NUM_LEDS2];
CRGB strip3[NUM_LEDS3];
//STRIP EVENT
int strip1Event;
int strip2Event;
int strip3Event;
//STRIP RGBS
int r1=0,g1=0,b1=0;
int r2=0,g2=0,b2=0;
int r3=0,g3=0,b3=0;
//STRIP COUNTERS
int strip1Count;
int strip2Count;
int strip3Count;
int strip1CountJ;
int strip2CountJ;
int strip3CountJ;
//VELOCITY
int Speed = 5;
void webSocketRun() {
}
void lightCall(){
//STRIP 1 EVENT
if(isActiveStrip1)
switch(strip1Event){
case 0:{
simpleRainbow(0,1);
}
break;
case 1:{
setAll(r1,g1,b1,1);
}
break;
case 2:{
sincroRainbow(0);
}
break;
}
//STRIP 2 EVENT
if(isActiveStrip2)
switch(strip2Event){
case 0:{
simpleRainbow(0,2);
}
break;
case 1:{
setAll(r2,g2,b2,2);
}
break;
case 2:{
}
break;
}
//STRIP 3 EVENT
if(isActiveStrip3)
switch(strip3Event){
case 0:{
simpleRainbow(0,3);
}
break;
case 1:{
setAll(r3,g3,b3,3);
}
break;
case 2:{
}
break;
}
}
//SETUP INFORMATIONS
void setup(){
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
Serial.println();
Serial.println();
Serial.println("LIGADO");
//INITIALIZE ALL STRIPS
FastLED.addLeds<WS2812B, PIN, GRB>(strip1, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2812B, PIN2, GRB>(strip2, NUM_LEDS2).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2812B, PIN3, GRB>(strip3, NUM_LEDS3).setCorrection( TypicalLEDStrip );
//Setup StartEvents
strip1Event=1;
strip2Event=2;
strip3Event=2;
//ADDING THREADS
threadRead.onRun(webSocketRun);
threadRead.setInterval(1);
threadLight.onRun(lightCall);
threadLight.setInterval(2);
controll.add(&threadRead);
controll.add(&threadLight);
}
void loop(){
controll.run();
}
//SHOW SPECIFC STRIP
void showStrip() {
FastLED.show();
}
//SET A SPECIFC PIXEL INTO A SPECIFC STRIP
void setPixel(int Pixel, byte red, byte green, byte blue, int stripID) {
if (stripID == 1) {
strip1[Pixel].r=red;
strip1[Pixel].g=green;
strip1[Pixel].b=blue;
}
else if (stripID == 2) {
strip2[Pixel].r=red;
strip2[Pixel].g=green;
strip2[Pixel].b=blue;
}
else if (stripID == 3) {
strip3[Pixel].r=red;
strip3[Pixel].g=green;
strip3[Pixel].b=blue;
}
}
//SET ALL PIXELS TO A SPECIFC STRIP
void setAll(byte red, byte green, byte blue, int stripID) {
int numberLeds;
if (stripID == 1) {
numberLeds = NUM_LEDS;
}
else if (stripID == 2) {
numberLeds = NUM_LEDS2;
}
else if (stripID == 3) {
numberLeds = NUM_LEDS3;
}
for (int i = 0; i < numberLeds; i++ ) {
setPixel(i, red, green, blue, stripID);
}
showStrip();
}
//LED EFFECTS ------------------------------------------------------------------------------------------------- x x x x x x x x x x x x ---------------------------------------------------------------------------------------------------------------
//WHEEL FOR RAINBOW
byte * Wheel(byte WheelPos) {
static byte c[3];
if (WheelPos < 85) {
c[0] = WheelPos * 3;
c[1] = 255 - WheelPos * 3;
c[2] = 0;
} else if (WheelPos < 170) {
WheelPos -= 85;
c[0] = 255 - WheelPos * 3;
c[1] = 0;
c[2] = WheelPos * 3;
} else {
WheelPos -= 170;
c[0] = 0;
c[1] = WheelPos * 3;
c[2] = 255 - WheelPos * 3;
}
return c;
}
void simpleRainbow(int SpeedDelay, int stripID) {
byte *c;
int contTempo;
int numberLeds;
int cont;
if (stripID == 1) {
contTempo = strip1Count;
strip1Count++;
numberLeds = NUM_LEDS;
cont = strip1CountJ;
}
else if (stripID == 2) {
contTempo = strip2Count;
strip2Count++;
numberLeds = NUM_LEDS2;
cont = strip2CountJ;
}
else if (stripID == 3) {
contTempo = strip3Count;
strip3Count++;
numberLeds = NUM_LEDS3;
cont = strip3CountJ;
}
if (contTempo >= SpeedDelay) {
for (int i = 0; i < numberLeds; i++) {
c = Wheel(((i * 256 / numberLeds) + cont) & 255);
setPixel(i, *c, *(c + 1), *(c + 2), stripID);
}
contTempo = 0;
if (stripID == 1) {
strip1Count = contTempo;
strip1CountJ++;
}
else if (stripID == 2) {
strip2Count = contTempo;
strip2CountJ++;
}
else if (stripID == 3) {
strip3Count = contTempo;
strip3CountJ++;
}
showStrip();
}
}
//SINCRO RAINBOW
void sincroRainbow(int SpeedDelay) {
byte *c;
int contTempo;
int numberLeds;
int cont;
numberLeds = NUM_LEDS + NUM_LEDS2 + NUM_LEDS3;
contTempo = strip1Count;
strip1Count++;
cont = strip1CountJ;
if (contTempo >= SpeedDelay) {
for (int i = 0; i <= numberLeds; i++) {
c = Wheel(((i * 256 / numberLeds) + cont) & 255);
if (i < NUM_LEDS) {
setPixel(i, *c, *(c + 1), *(c + 2), 1);
}
else if (i >= NUM_LEDS && i <= (NUM_LEDS + NUM_LEDS2)) {
setPixel(i - NUM_LEDS, *c, *(c + 1), *(c + 2), 2);
}
else if (i > NUM_LEDS2 && i <= numberLeds) {
setPixel(NUM_LEDS3 - (i - (NUM_LEDS + NUM_LEDS2)), *c, *(c + 1), *(c + 2), 3);
}
}
contTempo = 0;
strip1Count = contTempo;
strip1CountJ++;
showStrip();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment