Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



LED Effects - Ardui...
 
Share:
Notifications
Clear all

[Solved] LED Effects - Arduino and TwitchChat

44 Posts
2 Users
5 Reactions
11.7 K Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2741
Topic starter  

Makes sense! The client will call the callback.

Next time I'll make sure to drink some more coffee so I do not overlook that hahah ... 😉 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Hello and sorry for beeing so long not here! O_o

Now my 3rd attempt to write here. this constant SPAM suspicion is annoying!

I had something to do in life and yesterday my hardware finally arrived, the "WeMos 1 mini".

After soldering and the first idle test, I naturally copied the sketch directly onto the small one. After a greeting in the chat (as intended) nothing worked anymore. Just boot loop.

I then looked for some tips and tricks and tried them out. Now I came to the conclusion, with smaller sketches runs without boot loop, so I start again and lo and behold :) now no more boot loop and he also answers in chat as requested. Apparently it doesn't control the LEDs.

first of all my current newly composed sketch and of course the question

what could be the reason or how to test without neopixel? ;)

/****************************************************************
    Connect to Twtich Chat with a Bot

    and switch various FastLED Effects via Chat-Commands 
    the Bot answers in Chat
 *************************************************************/
#define FASTLED_INTERNAL // <-- add this line disable some of the messages in FastLED
#include <ESP8266WiFi.h>          //link to github /esp8266/Arduino
#include <IRCClient.h>
#include <FastLED.h>

//define your default values here.

#define IRC_SERVER   "irc.chat.twitch.tv"
#define IRC_PORT     6667

//------- Replace the following! ------
char ssid[] = "FRITZ!Box xxxxxxxxxx";       // your network SSID (name)
char password[] = "9849xxxxxxxxxx";  // your network key

//The name of the channel that you want the bot to join
const String twitchChannelName = "#ronxtcdabass";

//The name that you want the bot to have
#define TWITCH_BOT_NAME "beatsueppchenbot"

//OAuth Key for your twitch bot
// link to twitchapps.com/tmi/
#define TWITCH_OAUTH_TOKEN "oauth:xiqxxxxxxxxxx"
//------------------------------
// Define necessary parameters for controlling the WS2812B LEDs
#define NUM_LEDS  81
#define PIN   D6       // labeled "D6" on the board
#define LED_TYPE  WS2811
#define BRIGHTNESS  100     // a little dim for recording purposes
#define COLOR_ORDER GRB

// Declare the LED array
CRGB leds[NUM_LEDS];
  
//------------------------------
String RGBLoopMessage = "RGBLoop";
String FadeInOutMessage = "FadeInOut";
String StrobeMessage = "Strobe";
String HalloweenEyesMessage = "HalloweenEyes";
String CylonBounceMessage = "CylonBounce";
String NewKITTMessage = "NewKITT";
String TwinkleRandomMessage = "TwinkleRandom";
String TwinkleMessage = "TwinkleMessage";
String whiteSparkleMessage = "whiteSparkle";
String randomSparkleMessage = "randomSparkle";
String SnowSparkleMessage = "SnowSparkle";
String RunningLightsMessage = "RunningLights";
String colorWipeMessage = "colorWipe";
String rainbowCycleMessage = "rainbowCycle";
String theaterChaseMessage = "theaterChase";
String theaterChaseRainbowMessage = "theaterChaseRainbow";
String FireMessage = "Fire";
String BouncingBallsMessage = "BouncingBalls";
String BouncingColoredBallsMessage = "BouncingColoredBalls";
String meteorRainMessage = "meteorRain";

int led = LED_BUILTIN;
String ircChannel = "";

WiFiClient wiFiClient;
IRCClient client(IRC_SERVER, IRC_PORT, wiFiClient);

// put your setup code here, to run once:
void setup() {

  pinMode(led, OUTPUT);

  Serial.begin(115200);
  Serial.println();

  // Set WiFi to station mode and disconnect from an AP if it was Previously
  // connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  // Attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);

  ircChannel = twitchChannelName;

  client.setCallback(callback);
}

void loop() {

  // Try to connect to chat. If it loses connection try again
  if (!client.connected()) {
    Serial.println("Attempting to connect to " + ircChannel );
    // Attempt to connect
    // Second param is not needed by Twtich
    if (client.connect(TWITCH_BOT_NAME, "", TWITCH_OAUTH_TOKEN)) {
      client.sendRaw("JOIN " + ircChannel);
      Serial.println("connected and ready to rock");
      sendTwitchMessage("Ready to go Boss!");
    } else {
      Serial.println("failed... try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
    return;
  }
  client.loop();
}

void sendTwitchMessage(String message) {
  client.sendMessage(ircChannel, message);
}

// renamed "void loop" to "ShowEffect"
void ShowEffect(int selectedEffect) {
  // removed EEPROM functions here
 
  switch(selectedEffect) {
   
    case 0  : {
                // RGBLoop - no parameters
                RGBLoop();
                break;
              }

    case 1  : {
                // FadeInOut - Color (red, green. blue)
                FadeInOut(0xff, 0x00, 0x00); // red
                FadeInOut(0x00, 0xff, 0x00); // green
                FadeInOut(0x00, 0x00, 0xff); // blue
                break;
              }
             
    case 2  : {
                // Strobe - Color (red, green, blue), number of flashes, flash speed, end pause
                Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
                break;
              }

    case 3  : {
                // HalloweenEyes - Color (red, green, blue), Size of eye, space between eyes, fade (true/false), steps, fade delay, end pause
                HalloweenEyes(0xff, 0x00, 0x00,
                              1, 4,
                              true, random(5,50), random(50,150),
                              random(1000, 10000));
                HalloweenEyes(0xff, 0x00, 0x00,
                              1, 4,
                              true, random(5,50), random(50,150),
                              random(1000, 10000));
                break;
              }
             
    case 4  : {
                // CylonBounce - Color (red, green, blue), eye size, speed delay, end pause
                CylonBounce(0xff, 0x00, 0x00, 4, 10, 50);
                break;
              }
             
    case 5  : {
                // NewKITT - Color (red, green, blue), eye size, speed delay, end pause
                NewKITT(0xff, 0x00, 0x00, 8, 10, 50);
                break;
              }
             
    case 6  : {
                // Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false)
                Twinkle(0xff, 0xff, 0xff, 10, 100, false);
                break;
              }
             
    case 7  : {
                // TwinkleRandom - twinkle count, speed delay, only one (true/false)
                TwinkleRandom(20, 100, false);
                break;
              }
             
    case 8  : {
                // Sparkle - Color (red, green, blue), speed delay
                Sparkle(0xff, 0xff, 0xff, 0);
                break;
              }

    case 9  : {
                // RandomSparkle - Color (red, green, blue), speed delay
                Sparkle(random(0,255), random(0,255), random(0,255), 0);
                break;
              }
               
    case 10  : {
                // SnowSparkle - Color (red, green, blue), sparkle delay, speed delay
                SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
                break;
              }
             
    case 11 : {
                // Running Lights - Color (red, green, blue), wave dealy
                RunningLights(0xff,0x00,0x00, 50);  // red
                RunningLights(0x00,0xff,0x00, 50);  // green
                RunningLights(0x00,0x00,0xff, 50);  // blue
                break;
              }
             
    case 12 : {
                // colorWipe - Color (red, green, blue), speed delay
                colorWipe(0x00,0xff,0x00, 50);
                colorWipe(0x00,0x00,0x00, 50);
                break;
              }

    case 13 : {
                // rainbowCycle - speed delay
                rainbowCycle(20);
                break;
              }

    case 14 : {
                // theatherChase - Color (red, green, blue), speed delay
                theaterChase(0xff,0,0xff,50);
                break;
              }

    case 15 : {
                // theaterChaseRainbow - Speed delay
                theaterChaseRainbow(50);
                break;
              }

    case 16 : {
                // Fire - Cooling rate, Sparking rate, speed delay
                Fire(55,120,15);
                break;
              }

    case 17 : {
                // mimic BouncingBalls
                byte onecolor[1][3] = { {0xff, 0xff, 0xff} };
                BouncingColoredBalls(1, onecolor, false);
                break;
              }

    case 18 : {
                // multiple colored balls
                byte colors[3][3] = { {0xff, 0x00, 0x00},
                                      {0x00, 0xff, 0x00},
                                      {0x00, 0x00, 0xff} };
                BouncingColoredBalls(3, colors, false);
                break;
              }

    case 19 : {
                // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
                meteorRain(0xff,0x00,0xff,10, 64, true, 30);
                break;
              }
  }
}
// ---> here we define the effect function <---
// **********************
// ** LEDEffect Functions **
// *************************

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    // Fade IN
    for(int k = 0; k < 256; k++) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
    // Fade OUT
    for(int k = 255; k >= 0; k--) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
  }
}

void FadeInOut(byte red, byte green, byte blue){
  float r, g, b;
     
  for(int k = 0; k < 256; k=k+1) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }
     
  for(int k = 255; k >= 0; k=k-2) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }
}

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(FlashDelay);
  }
 
 delay(EndPause);
}

void HalloweenEyes(byte red, byte green, byte blue,
                   int EyeWidth, int EyeSpace,
                   boolean Fade, int Steps, int FadeDelay,
                   int EndPause){
  randomSeed(analogRead(0));
 
  int i;
  int StartPoint  = random( 0, NUM_LEDS - (2*EyeWidth) - EyeSpace );
  int Start2ndEye = StartPoint + EyeWidth + EyeSpace;
 
  for(i = 0; i < EyeWidth; i++) {
    setPixel(StartPoint + i, red, green, blue);
    setPixel(Start2ndEye + i, red, green, blue);
  }
 
  showStrip();
 
  if(Fade==true) {
    float r, g, b;
 
    for(int j = Steps; j >= 0; j--) {
      r = j*(red/Steps);
      g = j*(green/Steps);
      b = j*(blue/Steps);
     
      for(i = 0; i < EyeWidth; i++) {
        setPixel(StartPoint + i, r, g, b);
        setPixel(Start2ndEye + i, r, g, b);
      }
     
      showStrip();
      delay(FadeDelay);
    }
  }
 
  setAll(0,0,0); // Set all black
 
  delay(EndPause);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
 
  delay(ReturnDelay);
}

void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}

// used by NewKITT
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);
 
  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),red,green,blue);
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }
 
  delay(SpeedDelay);
}

void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);
 
  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }
 
  delay(SpeedDelay);
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

void randomSparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,random(0,255),random(0,255),random(0,255));
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
  setAll(red,green,blue);
 
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,0xff,0xff,0xff);
  showStrip();
  delay(SparkleDelay);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
}

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position=0;
 
  for(int i=0; i<NUM_LEDS*2; i++)
  {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }
     
      showStrip();
      delay(WaveDelay);
  }
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
  for(uint16_t i=0; i<NUM_LEDS; i++) {
      setPixel(i, red, green, blue);
      showStrip();
      delay(SpeedDelay);
  }
}

void rainbowCycle(int SpeedDelay) {
  byte *c;
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
      setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
  }
}

// used by rainbowCycle and theaterChaseRainbow
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 theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, red, green, blue);    //turn every third pixel on
      }
      showStrip();
     
      delay(SpeedDelay);
     
      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, 0,0,0);        //turn every third pixel off
      }
    }
  }
}

void theaterChaseRainbow(int SpeedDelay) {
  byte *c;
 
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < NUM_LEDS; i=i+3) {
          c = Wheel( (i+j) % 255);
          setPixel(i+q, *c, *(c+1), *(c+2));    //turn every third pixel on
        }
        showStrip();
       
        delay(SpeedDelay);
       
        for (int i=0; i < NUM_LEDS; i=i+3) {
          setPixel(i+q, 0,0,0);        //turn every third pixel off
        }
    }
  }
}

void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_LEDS];
  int cooldown;
 
  // Step 1.  Cool down every cell a little
  for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
   
    if(cooldown>heat[i]) {
      heat[i]=0;
    } else {
      heat[i]=heat[i]-cooldown;
    }
  }
 
  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for( int k= NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
  }
   
  // Step 3.  Randomly ignite new 'sparks' near the bottom
  if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
  }

  // Step 4.  Convert heat to LED colors
  for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }

  showStrip();
  delay(SpeedDelay);
}

void setPixelHeatColor (int Pixel, byte temperature) {
  // Scale 'heat' down from 0-255 to 0-191
  byte t192 = round((temperature/255.0)*191);
 
  // calculate ramp up from
  byte heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252
 
  // figure out which third of the spectrum we're in:
  if( t192 > 0x80) {                     // hottest
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) {             // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else {                               // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}

void BouncingColoredBalls(int BallCount, byte colors[][3], boolean continuous) {
  float Gravity = -9.81;
  int StartHeight = 1;
 
  float Height[BallCount];
  float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
  float ImpactVelocity[BallCount];
  float TimeSinceLastBounce[BallCount];
  int   Position[BallCount];
  long  ClockTimeSinceLastBounce[BallCount];
  float Dampening[BallCount];
  boolean ballBouncing[BallCount];
  boolean ballsStillBouncing = true;
 
  for (int i = 0 ; i < BallCount ; i++) {  
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0;
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
    ballBouncing[i]=true;
  }

  while (ballsStillBouncing) {
    for (int i = 0 ; i < BallCount ; i++) {
      TimeSinceLastBounce[i] =  millis() - ClockTimeSinceLastBounce[i];
      Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
 
      if ( Height[i] < 0 ) {                      
        Height[i] = 0;
        ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
        ClockTimeSinceLastBounce[i] = millis();
 
        if ( ImpactVelocity[i] < 0.01 ) {
          if (continuous) {
            ImpactVelocity[i] = ImpactVelocityStart;
          } else {
            ballBouncing[i]=false;
          }
        }
      }
      Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }

    ballsStillBouncing = false; // assume no balls bouncing
    for (int i = 0 ; i < BallCount ; i++) {
      setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]);
      if ( ballBouncing[i] ) {
        ballsStillBouncing = true;
      }
    }
   
    showStrip();
    setAll(0,0,0);
  }
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
    uint32_t oldColor;
    uint8_t r, g, b;
    int value;
   
    oldColor = strip.getPixelColor(ledNo);
    r = (oldColor & 0x00ff0000UL) >> 16;
    g = (oldColor & 0x0000ff00UL) >> 8;
    b = (oldColor & 0x000000ffUL);

    r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
    g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
    b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
   
    strip.setPixelColor(ledNo, r,g,b);
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue );
 #endif  
}

//  REPLACE TO HERE 


// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

void callback(IRCMessage ircMessage) {
  //Serial.println("In CallBack");

  if (ircMessage.command == "PRIVMSG" && ircMessage.text[0] != '\001') {
    //Serial.println("Passed private message.");
    ircMessage.nick.toUpperCase();

    String message("<" + ircMessage.nick + "> " + ircMessage.text);

    //prints chat to serial
    Serial.println(message);

    for (int i = 0; i < 6; i++) {
      digitalWrite(led, HIGH);
      delay(50);
      digitalWrite(led, LOW);
      delay(25);
    }

if(ircMessage.text == RGBLoopMessage)
  {  
  // example on how to call an effect:
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(0);
  }
  else if(ircMessage.text == FadeInOutMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(1);
  }
  else if(ircMessage.text == StrobeMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(2);
  }
  else if(ircMessage.text == HalloweenEyesMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(3);
  }
  else if(ircMessage.text == CylonBounceMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(4);
  }
  else if(ircMessage.text == NewKITTMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(5);
  }
  else if(ircMessage.text == TwinkleMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(6);
  }
  else if(ircMessage.text == TwinkleRandomMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(7);
  }
  else if(ircMessage.text == whiteSparkleMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(8);
  }
  else if(ircMessage.text == randomSparkleMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(9);
  }
  else if(ircMessage.text == SnowSparkleMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(10);
  }
  else if(ircMessage.text == RunningLightsMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(11);
  }
  else if(ircMessage.text == colorWipeMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(12);
  }
  else if(ircMessage.text == rainbowCycleMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(13);
  }
  else if(ircMessage.text == theaterChaseMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(14);
  }
  else if(ircMessage.text == theaterChaseRainbowMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(15);
  }
  else if(ircMessage.text == FireMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(16);
  }
  else if(ircMessage.text == BouncingBallsMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(17);
  }
  else if(ircMessage.text == BouncingColoredBallsMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(18);
  }
  else if(ircMessage.text == meteorRainMessage)
    {
  sendTwitchMessage(ircMessage.nick + " switching effect "  + ircMessage.text);
  ShowEffect(19);
  }

    return;
  }
  
}

 

I admit, I didn't buy an original Neopixel, but a broken Grundig light with 81 LEDs, (ebay /itm/394444649264)

which otherwise has some of the Neopixel effects and the LED strips also have 3 pins

[- Data +] with another original controller all of the Grundig is working.

how can I find out if they are even suitable ?

 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Sorry!!!!

i don´t know what happens with the code here O_o


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

I measured on the Grundig light, there are always 5V on the data line
[ +5V | Data (+5V) | GND ]

and with the WeMos apparently nothing at Pin D6 ... does it have to be like that?

But the WeMos has pin D4 for an external LED no matter how i try to map it.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2741
Topic starter  

Posted by: @Anonymous
Now my 3rd attempt to write here. this constant SPAM suspicion is annoying!

I'm sorry for the inconvenience - that is indeed super annoying 😞 
Unfortunately, the amount of spammers is getting worse and worse by the day, and the protection tools/services will never be perfect.

 

Posted by: @Anonymous
i don´t know what happens with the code here O_o

Optionally you can attach the INO file - not sure what happened with the code either haha. (will take a look after posting this reply)

 

Posted by: @Anonymous

I measured on the Grundig light, there are always 5V on the data line
[ +5V | Data (+5V) | GND ]

and with the WeMos apparently nothing at Pin D6 ... does it have to be like that?

But the WeMos has pin D4 for an external LED no matter how i try to map it.

Always 5V on the data line?
Interesting, that is not what I would expect?
I'd expect to see only 5V "peaks" when data is being uploaded.
The rest of the time I'd expect it to be 0V (I think the typical spec of 5V LED strips say something like < 0.7V, but I could be wrong).


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Hurra!! Hurraaa!   I´m a lil stupid :D :D :D

I´ve forgotten 1 Line in the new Sketch in the "void setup()" part...

FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

Now its working, but every effect freeze after a few seconds and fire shows almost nothing or only 1 Led.

 


   
Hans reacted
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

WhoooHooooo!!!!

here my nearly complete Sketch ;)

only the Bouncing Ball Effects seems not working correct.

and maybe each effect only active for ~30 secs. but not the single colors...

a lil more work is waiting ;)

for the moment - many many thanks to @hans

Posted by: @Anonymous

I measured on the Grundig light, there are always 5V on the data line
[ +5V | Data (+5V) | GND ]

yes. the Grundig seems never turned really OFF, only no effects ^^


   
Hans reacted
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

here a DEMO Video...

have fun! ;)

Youtube


   
Hans reacted
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2741
Topic starter  

Nice! Looks good! Glad to see it working! 👍🏻😊
(like the tunes as well 😉 )


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Yes, many thanks to you @hans, it's going so far.

 

ToDo List:

• the fine-tuning for the effects that cause the Wemos to crash

• Set all effects to a certain duration (20-30 sec.)

• Brightness by command? the default doesn't seem to work... "#define BRIGHTNESS 100"

• Is it possible to adjust the Rainbow Glitter (Neopixel) for this?

• Is it possible to additionally set a VU meter as a selectable effect?

• maybe later versions for Websocket? so users can unlock the effects with channel points

• and an adapted version for serial monitor, without WiFi... ... ...


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2741
Topic starter  

Tip for brightness, if I recall correctly (documentation);

byte brightness = 255; // 255 = max brightness, 0 = off

...

FastLED.setBrightness(brightness);

You may need to do a 

leds.show();

to make it visible.

 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Posted by: @hans

Tip for brightness, if I recall correctly (documentation);

byte brightness = 255; // 255 = max brightness, 0 = off

...

FastLED.setBrightness(brightness);

You may need to do a 

leds.show();

to make it visible.

Thanks very much!!!
what a shame O_o i think i´ve never read the doc... O_o

english is not my mothertongue... but i´m learning.

i will try to use this in 3 steps for the whole sketch... !bright !mid !dark...

 

Posted by: @Anonymous

ToDo List:

the fine-tuning for the effects that cause the Wemos to crash (no jumping balls anymore)

Set all effects to a certain duration 20-30 sec. (timer, counter & repeats)

Brightness by command? the default doesn't seem to work... "#define BRIGHTNESS 100"

Is it possible to adjust the Rainbow Glitter (from Neopixel) for this? (i found it ♥)

• Is it possible to additionally set a VU meter as a selectable effect?

• maybe later versions for Websocket? so users can unlock the effects with channel points

• and an adapted version for serial monitor, without WiFi... ... ...

 

 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Now i call 4 times the "Brightness" in this sketch...

Begin

#define LED_TYPE WS2811
#define BRIGHTNESS 100 // a little dim for recording purposes
#define COLOR_ORDER GRB

Message declaration

String BrightMessage = "!bright";
String MidMessage = "!mid";
String DarkMessage = "!dark";

in Setup

FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );

and at the END of the sketch

else if(ircMessage.text == BrightMessage)
{
FastLED.setBrightness(200); // 255 = max brightness, 0 = off
}
else if(ircMessage.text == MidMessage)
{
FastLED.setBrightness(100); // 255 = max brightness, 0 = off
}
else if(ircMessage.text == DarkMessage)
{
FastLED.setBrightness(40); // 255 = max brightness, 0 = off
}
return;
}

}

is this correct?

is there a better way?

 

it seems to work... call effect (normal) -> lights off -> brightness -> call effect = changed


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2741
Topic starter  

If it works ... 😁 
Like I said: you may need to add a leds.show(); -- not sure if it is needed.

Something like this to make it visible right away.

...
else if(ircMessage.text == DarkMessage)
{
  FastLED.setBrightness(40); // 255 = max brightness, 0 = off
  leds.show();
}

 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Haha ^^ if i use the "leds.show();" after "FastLED.setBrightness(xxx);"  it shows me errors... without is all right. :D

------------------------------------------------------------------------

Whoo! I discovered something, tried it for hours and still can't get it right.

I need help rebuilding / rewriting if possible...

String AchtungMessage = "Achtung!";
String WelcomeMessage = "VoHiYo";
String FollowMessage = "follow";
String SubMessage = "sub";
String BitsMessage = "bits";

/*
and the action
*/

else if(ircMessage.text == AchtungMessage)
  {
  Strobe(0xff, 0xff, 0, 10, 50, 1000);
  }

to

// startsWith() checks to see if a String starts with a particular substring:
String stringOne = "Achtung!";
Serial.println(stringOne);
if (stringOne.startsWith("Achtung!")) { // effect start }
String stringTwo = "VoHiYo";
Serial.println(stringTwo);
if (stringTwo.startsWith("VoHiYo")) { // other effect start }

and for follow, sub & bits

// Set up a String:
String stringThree = "Thank you for your follow...";
Serial.println(stringThree);

// substring(index) looks for the substring from the index position to the end:
if (stringThree.substring(19) == "follow") {// other effect start }

I despair because in my sketch so many functions are distributed from LOOP to CALLBACK and CLIENT.LOOP ...

If it works to recognize individual phrases from a whole text, I can unplug my old Arduino Nano from the USB and have one less program running when streaming, which consumes resources.

BUT PLEASE NOT IMMEDIATELY!   🤣 🤣 🤣

I won't get to anything else this weekend 🤣 🤣 🤣

So far it has been so funny, as soon as I unplugged the cable and closed the Arduino IDE, I was either allowed to read the next comment, or I found errors during the test run, which doesn't give me peace of mind. ^^

To-do list Brightness also done ✔

...


   
ReplyQuote
Page 2 / 3
Share: