Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define USE_OCTOWS2811
- #include<OctoWS2811.h>
- #include<FastLED.h>
- #include <SLIPEncodedSerial.h>
- #include <OSCMessage.h>
- String readString;
- // FastLED provides these pre-conigured incandescent color profiles:
- // Candle, Tungsten40W, Tungsten100W, Halogen, CarbonArc,
- // HighNoonSun, DirectSunlight, OvercastSky, ClearBlueSky,
- // FastLED provides these pre-configured gaseous-light color profiles:
- // WarmFluorescent, StandardFluorescent, CoolWhiteFluorescent,
- // FullSpectrumFluorescent, GrowLightFluorescent, BlackLightFluorescent,
- // MercuryVapor, SodiumVapor, MetalHalide, HighPressureSodium,
- // FastLED also provides an "Uncorrected temperature" profile
- // UncorrectedTemperature;
- #define TEMPERATURE UncorrectedTemperature
- DEFINE_GRADIENT_PALETTE( pink_gp ) {
- 0, 0, 0, 0, //Black
- 25, 255, 255, 255, //White
- 127, 255, 0, 255, //Pink
- 230, 128, 0, 128, //Purple
- 255, 0, 0, 0}; //Black
- DEFINE_GRADIENT_PALETTE( heatmap_gp ) {
- 0, 0, 0, 0, //black
- 85, 255, 0, 0, //red
- 170, 255,255, 0, //bright yellow
- 255, 0, 0, 0 }; //black
- DEFINE_GRADIENT_PALETTE( blink_purple_gp ) {
- 0, 0, 0, 0, //black
- 100, 255, 0, 255, //Purple
- 255, 0, 0, 0}; //Black
- DEFINE_GRADIENT_PALETTE( blink_orange_gp ) {
- 0, 0, 0, 0, //black
- 100, 255, 100, 0, //orange
- 255, 0, 0, 0}; //black
- DEFINE_GRADIENT_PALETTE( bg_orange_gp ) {
- 0, 0, 0, 0, //black
- 50, 0, 0, 0, //black
- 100, 255, 100, 0, //orange
- 205, 0, 0, 0, //black
- 255, 0, 0, 0}; //black
- DEFINE_GRADIENT_PALETTE( blink_bluetones_gp ) {
- 0, 0, 0, 0, //black
- 64, 33, 180, 226, //Dark blue
- 128, 109, 197, 224, //Light blue
- 192, 33, 180, 226, //Dark blue
- 255, 0, 0, 0}; //black
- CRGBPalette16 heatcolorPalette = heatmap_gp;
- CRGBPalette16 pinkPalette = pink_gp;
- CRGBPalette16 blinkPalettePurple = blink_purple_gp;
- CRGBPalette16 blinkPaletteOrange = blink_orange_gp;
- CRGBPalette16 blinkPaletteBluetones = blink_bluetones_gp;
- CRGBPalette16 bgPaletteOrange = bg_orange_gp;
- CRGBPalette16 rainbowPalette = RainbowColors_p;
- CRGBPalette16 * paletteArray[] = { &blinkPalettePurple, &blinkPaletteOrange, &blinkPaletteBluetones,&heatcolorPalette,&pinkPalette,&bgPaletteOrange, &rainbowPalette};
- #define NUM_LEDS_PER_STRIP 203
- #define NUM_STRIPS 8
- #define BRIGHTNESS 255
- CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
- SLIPEncodedSerial SLIPSerial(Serial1);
- enum pattern { NONE, BLOOMING, ENOGEN, TWINKLING, BLOOMING_RAINBOW, RAINBOW_THEATER_CHASE};
- enum mode { BLOMST, VU_METER, STREAM };
- enum direction { FORWARD, REVERSE };
- //LED-strip order
- const uint8_t blomst1BunnHullStart = 0;
- const uint8_t blomst1ToppHullStart = 1;
- const uint8_t blomst1BunnOmrissStart = 2;
- const uint8_t blomst1ToppOmrissStart = 3;
- const uint8_t blomst2BunnHullStart = 4;
- const uint8_t blomst2ToppHullStart = 5;
- const uint8_t blomst2BunnOmrissStart = 6;
- const uint8_t blomst2ToppOmrissStart = 7;
- //Forklaring paa nivaaer i arrayene
- //0 = Faktisk index i leds[] arrayen
- //1 = Rekkefolge i blooming-animasjonen
- //2 = Stilk eller blomst
- //3 = Next random blink time
- //4 = Index pr LED for hvor den er i random blinkanimasjon
- float blomst1Omriss [5][377];
- float blomst1Hull [5][290];
- float blomst2Omriss [5][377];
- float blomst2Hull [5][290];
- //Distanse mellom pixler i blomstene
- float distanse1 = 1.5;
- //startpixel for venstre blomst, bunn
- float vb_b = 31.0;
- //startpixel for hoyre blomst, bunn
- float hb_b = 35.0;
- float bunnHullRekkefolge [] = { 0.0,1.0,2.0,3.0,4.0,4.0,5.0,5.0,6.0,6.0,7.0,7.0,8.0,8.0,9.0,9.0,10.0,11.0,10.0,11.0,12.0,13.0,12.5,13.5,14.0,16.0,15.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0, //Stilk
- vb_b+(2*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(3*distanse1),vb_b+(1*distanse1),vb_b+(1*distanse1),vb_b+(1*distanse1),vb_b+(3*distanse1), //Blomst venstre
- 28.0,28.0, //Stilk
- vb_b+(2*distanse1),vb_b+(1*distanse1),vb_b,vb_b+(1*distanse1),vb_b+(1*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(3*distanse1), //Blomst venstre
- 29.0,29.0,30.0,31.0,32.0,33.0, //Stilk
- hb_b+(2*distanse1), //Blomst hoyre
- 32.0, //Stilk
- hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(1*distanse1),hb_b+(1*distanse1), //Blomst hoyre
- 33.0, //Stilk
- hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(1*distanse1),hb_b+(1*distanse1),hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(1*distanse1),hb_b,hb_b+(1*distanse1),hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(2*distanse1) //Blomst hoyre
- };
- //Distanse mellom pixler i blomst
- float distanse2 = 1.5;
- //startpixel for blomst1, topp
- float b1_t = 37.0;
- //startpixel for blomst2, topp
- float b2_t = 56.0;
- //startpixel for blomst3, topp
- float b3_t = 60.5;
- //startpixel for blomst4, topp
- float b4_t = 61.5;
- float toppHullRekkefolge [] = {
- //Stilk
- 34,34,
- //Blomst1
- b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(3.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),
- b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),
- b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(4.0*distanse2),b1_t+(3.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),
- b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(3.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),
- b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(3.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),
- b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(3.0*distanse2),b1_t+(2.0*distanse2),b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t,
- b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),
- b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),
- //Stilk
- 40,40.5,41.5,42.5,43,44,44.5,45.5,45.5,46.5,46.5,47.5,47.5,48.5,48.5,49.5,49.5,50.5,50.5,51,51.5,52,53,
- //Blomst2
- b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(1.0*distanse1),b2_t+(1.0*distanse1),
- b2_t+(1.0*distanse1),b2_t,b2_t+(1.0*distanse1),b2_t+(1.0*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(1.0*distanse1),
- b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),
- //Stilk
- 54,53,53,52.5,53.5,53.5,54.5,54.5,55.5,55.5,55.5,56.5,57.5,
- //Blomst 3
- b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(2.5*distanse1),b3_t+(1.0*distanse1),
- b3_t+(1.0*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(1.0*distanse1),b3_t,b3_t+(1.0*distanse1),b3_t+(1.0*distanse1),b3_t+(1.0*distanse1),b3_t+(2.5*distanse1),
- b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),
- //Stilk
- 58.5,57.5,56.5,56.5,56.5,57.5,58.5,
- //Blomst4
- b4_t,b4_t+(1.0*distanse2),
- //Stilk
- 59.5,
- //Blomst4
- b4_t+(2.0*distanse2),b4_t+(1.0*distanse2),b4_t+(3.0*distanse2),b4_t+(2.5*distanse2),b4_t+(4.0*distanse2),b4_t+(5.0*distanse2),b4_t+(3.0*distanse2),b4_t+(3.5*distanse2),b4_t+(5.0*distanse2),
- b4_t+(5.5*distanse2),b4_t+(5.5*distanse2),b4_t+(5.5*distanse2),b4_t+(5.0*distanse2),b4_t+(5.5*distanse2),b4_t+(6.0*distanse2),b4_t+(6.5*distanse2),b4_t+(7.0*distanse2),b4_t+(7.0*distanse2),
- b4_t+(6.5*distanse2),b4_t+(6.0*distanse2),b4_t+(5.5*distanse2),b4_t+(4.5*distanse2),b4_t+(2.5*distanse2),b4_t+(0.5*distanse2),b4_t+(1.5*distanse2),b4_t+(3.5*distanse2),b4_t+(5.5*distanse2),
- b4_t+(5.7*distanse2),b4_t+(6.0*distanse2),b4_t+(6.5*distanse2),b4_t+(6.5*distanse2),b4_t+(6.0*distanse2),b4_t+(5.0*distanse2),b4_t+(4.5*distanse2),b4_t+(4.0*distanse2),b4_t+(3.0*distanse2),
- //Stilk
- 60.5,59.5,58.5,58.0,57
- };
- class LedsMultitask
- {
- public:
- pattern ActivePattern1;
- mode ActiveMode;
- direction Direction;
- bool EndOfPattern;
- unsigned long Interval1;
- unsigned long Interval2;
- unsigned long lastUpdate1;
- unsigned long lastUpdate2;
- uint8_t Hue1;
- uint8_t Value1;
- uint8_t Saturation1;
- uint8_t Hue2;
- uint8_t Value2;
- uint8_t Saturation2;
- uint8_t IncrementSat;
- uint8_t IncrementVal;
- float Delta;
- float Index1;
- float Increment_by1;
- float Index2;
- float Increment_by2;
- uint16_t TotalSteps1;
- uint16_t TotalSteps2;
- uint8_t SegmentColorRed;
- uint8_t SegmentColorGreen;
- uint8_t SegmentColorBlue;
- uint8_t NumberOfStrips;
- uint8_t LedsPerStrip;
- uint16_t Pixels;
- boolean UpdatePattern;
- boolean Flash;
- boolean Dim;
- uint8_t PixelDistance;
- uint8_t PixelWidth;
- uint8_t TailLength;
- uint32_t BlinkRandomTime;
- uint32_t NextBlink_LEDi[NUM_LEDS_PER_STRIP * NUM_STRIPS];
- CRGBPalette16 * ActivePalette1;
- CRGBPalette16 * ActivePalette2;
- LedsMultitask(mode displaymode)
- {
- Pixels = NUM_LEDS_PER_STRIP * NUM_STRIPS;
- ActiveMode = displaymode;
- }
- // Update the pattern (hull)
- void Update1()
- {
- Serial.println("Update1");
- if ((millis() - lastUpdate1) > Interval1) // time to update
- {
- lastUpdate1 = millis();
- switch (ActivePattern1)
- {
- case BLOOMING:
- BloomingUpdate();
- break;
- case TWINKLING:
- TwinklingUpdate();
- break;
- case BLOOMING_RAINBOW:
- BloomingRainbowUpdate();
- break;
- case RAINBOW_THEATER_CHASE:
- RainbowTheaterChaseUpdate();
- break;
- default:
- break;
- }
- }
- }
- // Update the pattern (omriss)
- void Update2()
- {
- if ((millis() - lastUpdate2) > Interval2) // time to update
- {
- lastUpdate2 = millis();
- switch (ActivePattern1)
- {
- case BLOOMING:
- case TWINKLING:
- case BLOOMING_RAINBOW:
- OmrissUpdate();
- break;
- default:
- break;
- }
- }
- }
- void ResetHull () {
- for (int i = 0; i < 290; i++) {
- leds[(int)blomst1Hull[0][i]] = CRGB::Black;
- leds[(int)blomst2Hull[0][i]] = CRGB::Black;
- }
- }
- void ResetAllLEDs () {
- for (int i = 0; i < NUM_STRIPS*NUM_LEDS_PER_STRIP; i++) {
- leds[i] = CRGB::Black;
- }
- }
- // Increment the Index and reset at the end
- void Increment(float *index, uint16_t *total_steps, float *increment_by)
- {
- *index = *index + *increment_by;
- if (*index >= *total_steps)
- {
- *index = 0;
- }
- }
- void RainbowTheaterChase(direction dir = FORWARD)
- {
- ActivePattern1 = RAINBOW_THEATER_CHASE;
- TotalSteps1 = 290;
- TotalSteps2 = 100;
- Increment_by1 = 1;
- Increment_by2 = 0.5;
- Interval1 = 25;
- Hue1 = 15;
- Hue2 = 160;
- Saturation1 = 255;
- Saturation2 = 255;
- Value1 = 255;
- Value2 = 0;
- Index1 = 0;
- Index2 = 0;
- PixelDistance = 5;
- PixelWidth = 1;
- Direction = FORWARD;
- }
- void RainbowTheaterChaseUpdate()
- {
- uint8_t tail = 0;
- float dist;
- for(int i=0; i< TotalSteps1; i++)
- {
- dist = abs(((blomst1Hull[1][i]) - Index2));
- if (dist < Delta)
- {
- if ((i + (int)Index1) % PixelDistance == 0)
- {
- leds[(int)blomst1Hull[0][i]] = CHSV((i*10)%255, Saturation1, (Delta-dist)*(255/Delta));
- leds[(int)blomst2Hull[0][i]] = CHSV((i*10)%255, Saturation1, (Delta-dist)*(255/Delta));
- tail = PixelWidth;
- }
- else if (tail != 0)
- {
- leds[(int)blomst1Hull[0][i]] = CHSV((((i*10)-(PixelWidth-(tail*3)+1)))%255, Saturation1, (Delta-dist)*(255/Delta));
- leds[(int)blomst2Hull[0][i]] = CHSV((((i*10)-(PixelWidth-(tail*3)+1)))%255, Saturation1, (Delta-dist)*(255/Delta));
- //Serial.println(tail);
- tail--;
- }
- else
- {
- leds[(int)blomst1Hull[0][i]] = CHSV(Hue2, Saturation2, Value2);
- leds[(int)blomst2Hull[0][i]] = CHSV(Hue2, Saturation2, Value2);
- }
- }
- else {
- leds[(int)blomst1Hull[0][i]] = CRGB::Black;
- leds[(int)blomst2Hull[0][i]] = CRGB::Black;
- }
- }
- FastLED.show();
- Increment(&Index1, &TotalSteps1, &Increment_by1);
- Increment(&Index2, &TotalSteps2, &Increment_by2);
- }
- void Blooming()
- {
- ActiveMode = BLOMST;
- ActivePattern1 = BLOOMING;
- //Hull
- Delta = 4;
- Interval1 = 1;
- Index1 = 0;
- Increment_by1 = 0.08;
- TotalSteps1 = 100;
- Hue1 = 50;
- Hue2 = 100;
- Saturation1 = 255;
- //Omriss
- Interval2 = 50;
- Index2 = 0;
- TotalSteps2 = 255;
- Increment_by2 = 1;
- ActivePalette2 = &bgPaletteOrange;
- //Zero all LEDs
- ResetAllLEDs();
- LEDS.show();
- Serial.println("Blooming");
- }
- void BloomingUpdate()
- {
- Serial.println("BloomingUpdate");
- //Hull
- float dist;
- for (int x = 0; x < 290; x++)
- {
- dist = abs(((blomst1Hull[1][x]) - Index1));
- if (dist < Delta)
- {
- if ((int)blomst1Hull[2][x]==0) {
- leds[(int)blomst1Hull[0][x]] = CHSV(Hue1,Saturation1,(Delta-dist)*(255/Delta));
- leds[(int)blomst2Hull[0][x]] = CHSV(Hue1,Saturation1,(Delta-dist)*(255/Delta));
- }
- else {
- leds[(int)blomst1Hull[0][x]] = CHSV(Hue2,Saturation1,(Delta-dist)*(255/Delta));
- leds[(int)blomst2Hull[0][x]] = CHSV(Hue2,Saturation1,(Delta-dist)*(255/Delta));
- }
- }
- else {
- leds[(int)blomst1Hull[0][x]] = CRGB::Black;
- leds[(int)blomst2Hull[0][x]] = CRGB::Black;
- }
- }
- Increment(&Index1, &TotalSteps1, &Increment_by1);
- FastLED.show();
- }
- void OmrissUpdate()
- {
- for (int i = 0; i < 377; i++) {
- uint8_t palette_index = (int)Index2+i;
- //leds[(int)blomst1Omriss[0][i]] = CHSV(hue,255,255);
- leds[(int)blomst1Omriss[0][i]] = ColorFromPalette(*ActivePalette2,palette_index);
- leds[(int)blomst2Omriss[0][i]] = ColorFromPalette(*ActivePalette2,palette_index);
- }
- Increment(&Index2, &TotalSteps2, &Increment_by2);
- FastLED.show();
- }
- void Twinkling()
- {
- ActivePattern1 = TWINKLING;
- //Hull
- Interval1 = 1;
- Index1 = 0;
- Increment_by1 = 1;
- TotalSteps1 = 255;
- Hue2 = 100;
- BlinkRandomTime = 10000;
- Value1 = 100;
- Saturation2 = 255;
- ActivePalette1 = &blinkPaletteOrange;
- //Omriss
- Interval2 = 50;
- Index2 = 0;
- TotalSteps2 = 255;
- Increment_by2 = 1;
- ActivePalette2 = &bgPaletteOrange;
- for (int i = 0; i < 290; i++) {
- //Nullstiller index for alle LEDs
- blomst1Hull[4][i] = 0;
- blomst2Hull[4][i] = 0;
- //Gir random startverdier til pixels i blomsterhodene
- NextBlink_LEDi[(int)blomst1Hull[0][i]] = millis()+(random16()%BlinkRandomTime);
- NextBlink_LEDi[(int)blomst2Hull[0][i]] = millis()+(random16()%BlinkRandomTime);
- }
- //Zero all LEDs
- ResetAllLEDs();
- FastLED.show();
- Serial.println("Twinkling");
- }
- void TwinklingUpdate()
- {
- for (int i = 0; i < 290; i++)
- {
- if (blomst1Hull[2][i] == 0 ) //Hvis blomst
- {
- if (millis() >= NextBlink_LEDi[(int)blomst1Hull[0][i]])
- {
- leds[(int)blomst1Hull[0][i]] = ColorFromPalette( *ActivePalette1, (int)blomst1Hull[4][i]);
- leds[(int)blomst2Hull[0][i]] = ColorFromPalette( *ActivePalette1, (int)blomst1Hull[4][i]); //Sets color of LED according to position in ActivePalette
- blomst1Hull[4][i]++; //Increases Index by 1
- blomst2Hull[4][i]++;
- //Checks if we have run through the entire color palette
- if (blomst1Hull[4][i] >= TotalSteps1)
- {
- blomst1Hull[4][i] = 0;
- blomst2Hull[4][i] = 0; //Resets the index to 0
- NextBlink_LEDi[(int)blomst1Hull[0][i]] = (millis()+(random16()%BlinkRandomTime)); //Generates a new time for the next blink
- NextBlink_LEDi[(int)blomst2Hull[0][i]] = (millis()+(random16()%BlinkRandomTime));
- }
- }
- }
- else
- { //Hvis stilk
- leds[(int)blomst1Hull[0][i]] = CHSV(Hue2,Saturation2,Value1);
- leds[(int)blomst2Hull[0][i]] = CHSV(Hue2,Saturation2,Value1);
- }
- }
- FastLED.show();
- }
- void BloomingRainbow()
- {
- //Hull
- Interval1 = 30;
- ActivePattern1 = BLOOMING_RAINBOW;
- Value1 = 255;
- Saturation1 = 255;
- Saturation2 = 0;
- TotalSteps1 = 100;
- Index1 = 0;
- Increment_by1 = 1;
- Delta = 4;
- //Omriss
- ActivePalette2 = &rainbowPalette;
- //Zero all LEDs
- //ResetAllLEDs();
- //FastLED.show();
- Serial.println("BloomingRainbow");
- }
- void BloomingRainbowUpdate()
- {
- //Hull
- float dist;
- for (int x = 0; x < 290; x++)
- {
- dist = abs(((blomst1Hull[1][x]) - Index1));
- if (dist < Delta) {
- if ((int)blomst1Hull[2][x]==0) {
- leds[(int)blomst1Hull[0][x]] = CHSV((int)(Index1+x)%255,Saturation1,(Delta-dist)*(255/Delta));
- leds[(int)blomst2Hull[0][x]] = CHSV((int)(Index1+x)%255,Saturation1,(Delta-dist)*(255/Delta));
- }
- else {
- leds[(int)blomst1Hull[0][x]] = CHSV((int)(Index1+x)%255,Saturation1,(Delta-dist)*(255/Delta));
- leds[(int)blomst2Hull[0][x]] = CHSV((int)(Index1+x)%255,Saturation1,(Delta-dist)*(255/Delta));
- }
- }
- else {
- leds[(int)blomst1Hull[0][x]] = CRGB::Black;
- leds[(int)blomst2Hull[0][x]] = CRGB::Black;
- }
- }
- Increment(&Index1, &TotalSteps1, &Increment_by1);
- FastLED.show();
- Serial.println("BloomingRainbowUpdate");
- }
- void updateInterval(unsigned long interval)
- {
- Interval1 = interval;
- }
- void updateValue1(uint8_t value)
- {
- Value1 = value;
- }
- void updateValue2(uint8_t value)
- {
- Value2 = value;
- }
- void updateHue1(uint8_t hue)
- {
- Hue1 = hue;
- }
- void updateHue2(uint8_t hue)
- {
- Hue2 = hue;
- }
- void updateSaturation1(uint8_t sat)
- {
- Saturation1 = sat;
- }
- void updateSaturation2(uint8_t sat)
- {
- Saturation2 = sat;
- }
- void updatePatternFunction()
- {
- UpdatePattern = 1;
- }
- void updateColor1(uint8_t x, uint8_t y)
- {
- Saturation1 = x;
- Hue1 = y;
- }
- void updateColor2(uint8_t x, uint8_t y)
- {
- Saturation2 = x;
- Hue2 = y;
- }
- void changeActiveMode(int x)
- {
- switch (x)
- {
- case 1:
- ActiveMode = BLOMST;
- break;
- case 2:
- ActiveMode = VU_METER;
- break;
- case 3:
- ActiveMode = STREAM;
- break;
- default:
- break;
- }
- }
- void changeDirection(uint8_t x)
- {
- switch (x)
- {
- case 1:
- Direction = FORWARD;
- break;
- case 2:
- Direction = REVERSE;
- break;
- default:
- break;
- }
- }
- void updatePixelDistance(uint8_t x)
- {
- PixelDistance = x;
- }
- void updatePixelWidth(uint8_t x)
- {
- PixelWidth = x;
- }
- void updateTailLength(uint8_t x)
- {
- TailLength = x;
- }
- void updateBlinkRandomTime(uint32_t x)
- {
- BlinkRandomTime = x;
- }
- void SetActivePalette1(int x) {
- ActivePalette1 = paletteArray[x];
- ResetHull();
- }
- void SetActivePalette2(int x) {
- ActivePalette2 = paletteArray[x];
- }
- };
- LedsMultitask Ledstrip(BLOMST);
- void setup() {
- Serial.begin(9600); //Teensy <=> Computer
- SLIPSerial.begin(115200); //Teensy <=> ESP
- delay(1000);
- Serial.println("Started");
- FastLED.addLeds<OCTOWS2811>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalSMD5050 );
- FastLED.setTemperature( TEMPERATURE );
- LEDS.setBrightness(BRIGHTNESS);
- LedArrayMaker();
- Ledstrip.BloomingRainbow();
- //Reset all LEDs
- for (int i = 0; i < NUM_LEDS_PER_STRIP*NUM_STRIPS;i++) {
- leds[i] = CRGB::Black;
- }
- FastLED.show();
- }
- void loop() {
- Serial.println("loop");
- //OSCMsgReceive();
- //Ledstrip.Update1();
- //Ledstrip.Update2();
- /*
- while (Serial.available())
- {
- Serial.println("Reading serial");
- char c = Serial.read(); //gets one byte from serial buffer
- readString += c; //makes the string readString
- delay(2); //slow looping to allow buffer to fill with next character
- }
- if (readString.length() >0)
- {
- Serial.println(readString); //so you can see the captured string
- int n = readString.toInt(); //convert readString into a number
- Serial.print("Lyser opp LED nr: ");
- Serial.println(n);
- for (int i = 0; i < 290; i++)
- {
- if (i == n) {
- leds[(int)blomst1Hull[0][i]] = CRGB::White;
- }
- else {
- leds[(int)blomst1Hull[0][i]] = CRGB::Black;
- }
- }
- FastLED.show();
- }
- readString=""; //empty for next input
- */
- }
- void OSCMsgReceive()
- {
- OSCMessage msgIN;
- int size;
- static unsigned long microsTime = 0;
- while (!SLIPSerial.endofPacket())
- {
- if ((size = SLIPSerial.available()) > 0)
- {
- microsTime = micros();
- while (size--) //this needs a byte limit
- {
- msgIN.fill(SLIPSerial.read());
- }
- }
- if ((micros() - microsTime) > 10000) break; //Timeout for no eoP()
- }
- if(!msgIN.hasError())
- {
- //Serial.println("Routing OSC message");
- msgIN.route("/Mode",changeLEDMode);
- msgIN.route("/Fader",funcValue);
- }
- }
- void changeLEDMode(OSCMessage &msg, int addrOffset ){
- //Serial.println("Changing LED mode");
- //PROGRAMS
- if(msg.fullMatch("/Mode/blooming"))
- {
- Ledstrip.Blooming();
- FastLED.delay(20);
- }
- if(msg.fullMatch("/Mode/twinkling"))
- {
- Ledstrip.Twinkling();
- FastLED.delay(20);
- }
- if(msg.fullMatch("/Mode/blooming_rainbow"))
- {
- Ledstrip.BloomingRainbow();
- FastLED.delay(20);
- }
- if(msg.fullMatch("/Mode/rainbow_theater"))
- {
- Ledstrip.RainbowTheaterChase();
- FastLED.delay(20);
- }
- //PARAMETERS
- if(msg.fullMatch("/Mode/direction"))
- {
- float value = msg.getFloat(0);
- Ledstrip.changeDirection((int)value);
- }
- //DISPLAY MODES
- if(msg.fullMatch("/Mode/displaymode/blomst"))
- {
- Ledstrip.changeActiveMode(1);
- }
- if(msg.fullMatch("/Mode/displaymode/vu_meter"))
- {
- Ledstrip.changeActiveMode(2);
- }
- if(msg.fullMatch("/Mode/displaymode/stream"))
- {
- Ledstrip.changeActiveMode(3);
- }
- }
- void funcValue(OSCMessage &msg, int addrOffset ){
- //OSCMessage msgOUT("/Fader");
- Ledstrip.updatePatternFunction();
- // INTERVAL
- if (msg.fullMatch("/Fader/interval"))
- {
- float value = msg.getFloat(0);
- Ledstrip.updateInterval((int)value);
- }
- // Value (brightness)
- if (msg.fullMatch("/Fader/value1"))
- {
- float value = msg.getFloat(0);
- Ledstrip.updateValue1((int)value);
- }
- if (msg.fullMatch("/Fader/value2"))
- {
- float value = msg.getFloat(0);
- Ledstrip.updateValue2((int)value);
- }
- // HUE
- if (msg.fullMatch("/Fader/hue1"))
- {
- float value = msg.getFloat(0);
- Ledstrip.updateHue1((int)value);
- }
- if (msg.fullMatch("/Fader/hue2"))
- {
- float value = msg.getFloat(0);
- Ledstrip.updateHue2((int)value);
- }
- // SATURATION
- if (msg.fullMatch("/Fader/saturation1"))
- {
- float value = msg.getFloat(0);
- Ledstrip.updateSaturation1((int)value);
- }
- if (msg.fullMatch("/Fader/saturation2"))
- {
- float value = msg.getFloat(0);
- Ledstrip.updateSaturation2((int)value);
- }
- // COLOR (will replace hue and saturation)
- if (msg.fullMatch("/Fader/color1"))
- {
- float x = msg.getFloat(0);
- float y = msg.getFloat(1);
- Ledstrip.updateColor1((uint8_t)x, (uint8_t)y);
- }
- if (msg.fullMatch("/Fader/color2"))
- {
- float x = msg.getFloat(0);
- float y = msg.getFloat(1);
- Ledstrip.updateColor2((uint8_t)x, (uint8_t)y);
- }
- if (msg.fullMatch("/Fader/palette1"))
- {
- int x = (int)msg.getFloat(0);
- if (x != -1) {
- Ledstrip.SetActivePalette1(x);
- }
- }
- if (msg.fullMatch("/Fader/palette2"))
- {
- int x = (int)msg.getFloat(0);
- if (x != -1) {
- Ledstrip.SetActivePalette2(x);
- }
- }
- }
- void LedArrayMaker()
- {
- //Hull bunn, begge blomster
- for (int i = 0; i < 87; i++) {
- blomst1Hull[0][i] = (blomst1BunnHullStart*NUM_LEDS_PER_STRIP)+i;
- blomst2Hull[0][i] = (blomst2BunnHullStart*NUM_LEDS_PER_STRIP)+i;
- blomst1Hull[1][i] = bunnHullRekkefolge[i];
- blomst2Hull[1][i] = bunnHullRekkefolge[i];
- //Definerer hva som er blomster
- if ( ((i > 37) && (i < 50)) || ((i > 51) && (i < 62)) ) {
- blomst1Hull[2][i] = 0;
- blomst2Hull[2][i] = 0;
- }
- //Definerer hva som er blomster
- else if ( (i==68) || ((i>69) && (i<74)) || ((i>74)&&(i<87)) ) {
- blomst1Hull[2][i] = 0;
- blomst2Hull[2][i] = 0;
- }
- //Definerer hva som er stilk
- else {
- blomst1Hull[2][i] = 1;
- blomst2Hull[2][i] = 1;
- }
- }
- //Hull topp, begge blomster
- for (int i = 0; i < 203; i++) {
- int x = 87 + i;
- blomst1Hull[0][x] = (blomst1ToppHullStart*NUM_LEDS_PER_STRIP)+i;
- blomst2Hull[0][x] = (blomst2ToppHullStart*NUM_LEDS_PER_STRIP)+i;
- blomst1Hull[1][x] = toppHullRekkefolge[i];
- blomst2Hull[1][x] = toppHullRekkefolge[i];
- //Definerer hva som er blomster
- if ( ((x>88) && (x<154)) || ((x>176) && (x<200)) || ((x>212) && (x<239)) || ((x>245) && (x<248)) || ((x>248) && (x<285)) ) {
- blomst1Hull[2][x] = 0;
- blomst2Hull[2][x] = 0;
- }
- //Definerer hva som er stilk
- else {
- blomst1Hull[2][x] = 1;
- blomst2Hull[2][x] = 1;
- }
- }
- //Omriss blomst1 bunn
- for (int i = 0; i < 187; i++) {
- blomst1Omriss[0][i] = (blomst1BunnOmrissStart*NUM_LEDS_PER_STRIP)+i;
- }
- //Omriss blomst1 topp
- for (int i = 0; i < 189; i++) {
- blomst1Omriss[0][i+188] = (blomst1ToppOmrissStart*NUM_LEDS_PER_STRIP)+i;
- }
- //Omriss blomst2 bunn
- for (int i = 0; i < 187; i++) {
- blomst2Omriss[0][i] = (blomst2BunnOmrissStart*NUM_LEDS_PER_STRIP)+i;
- }
- //Omriss blomst2 topp
- for (int i = 0; i < 187; i++) {
- blomst2Omriss[0][i+188] = (blomst2ToppOmrissStart*NUM_LEDS_PER_STRIP)+i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement