LED patterns with zeRGBa

Hello! I’m trying to program an RGB LED.

I have a button that, when pressed, runs a simple RGB fade through all the colors.

I also want to be able to control the RGB LED with zeRGBa, but the two don’t seem to be playing nice with each other. Unless I set zeRGBa to completely off or black before pressing the fade button, the color fade pattern doesn’t start run correctly from all LEDs in the LOW state and often causes the ESP8266 I’m using to restart.

Is there something I can do to improve my code? I’ve replaced the fade pattern with a simple flash pattern that I saw somewhere else on the forum for the sake of debugging.

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define RED 12
#define GREEN 13
#define BLUE 14
int const delayTime = 100;

char auth[] = "**********************************";

int mode ;
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;

void setup()
{
  mode = 0; // Start in a known state
  
  Serial.begin(9600);
  Blynk.begin(auth, "**********", "*********************");

  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(RED, OUTPUT);
  digitalWrite(GREEN, LOW);
  digitalWrite(BLUE, LOW);
  digitalWrite(RED, LOW);
}

BLYNK_WRITE(1) 
{
 // Change state on button press 
 if( param.asInt() == 1 ) {
  digitalWrite(GREEN, LOW);
  digitalWrite(BLUE, LOW);
  digitalWrite(RED, LOW);
  mode = 1 ; 
 } else {
  mode = 0 ; 
 } 
}

void colorChange() {

  digitalWrite(RED, HIGH);
  delay(delayTime);
  digitalWrite(RED, LOW);
  delay(delayTime);
  digitalWrite(GREEN, HIGH);
  delay(delayTime);
  digitalWrite(GREEN, LOW);
  delay(delayTime);
  digitalWrite(BLUE, HIGH);
  delay(delayTime);
  digitalWrite(BLUE, LOW);
  delay(delayTime);
}

void loop()
{
  Blynk.run();
  
  switch( mode ) {
    case 1:
      colorChange();
      break; 

    defaul: {
      // Do nothing 
    }
  }
}

Hello. So do you use zergba or not for that sketch? If - yes - you need to delete all delays within colorChange function. Also if you use zergba for digital pins you don’t need to set pin modes for pins you configured in zergba.

Thank you for your help!
I think I’ve almost got what I want working!!

Hey,
I was also trying something similar. Could you share your code if you got it working.
Thanks

1 Like

@ganna.ramu Please make note of time date stamps before posting… this topic is over a year and half old… as was last post from this user :wink:

1 Like

@Gunner I had taken note of it, but was just hoping i would get help. Thanks for the information :grin::grin:

Create a new topic… detail what you are trying to do and what you have ALREADY tried (please don’t just ask for someone else to show/do it for you) and you will get the assistance as needed.