(Code for) ZeRGBa NOT WORKING

I have tried all that i can but i can’t manage to get the Zergba to work, it seems that it nevers sends the values, when i tell the esp8266 to print the values of Zergba it always tells me 0, i don’t know what else to do.

#define BLYNK_PRINT Serial
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Ticker.h>
Adafruit_BME280 bme;
char auth[] = "1daa8c06625xxxxxxdd5cebdea61";
char ssid[] = "ASUS";
char pass[] = "*******";
Ticker timer;
const byte rmax = 500;
const byte gmax = 500;
const byte bmax = 500;
unsigned int Rpwm = 0;
unsigned int Gpwm = 0;
unsigned int Bpwm = 0;
int r;
int g;
int b;
byte i = 0;
bool A = false;
BLYNK_WRITE(V1) {
 int r = param[0].asInt();
 int g = param[1].asInt();
 int b = param[2].asInt();
}
void setup()
{
  Wire.begin(5, 4);
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  bme.begin(0x76);
  bme.setSampling(Adafruit_BME280::MODE_FORCED,
                  Adafruit_BME280::SAMPLING_X1, // temperature
                  Adafruit_BME280::SAMPLING_X1, // pressure
                  Adafruit_BME280::SAMPLING_X1, // humidity
                  Adafruit_BME280::FILTER_OFF   );
  pinMode(12, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  timer.attach(20, ReadSensor);
  //WidgetLCD lcd(V9);
  delay(100);
}

void loop()
{
  WidgetLCD lcd(V9);
  Blynk.run();
  Rpwm = map(r, 0, 1023, 0, rmax);
  Gpwm = map(g, 0, 1023, 0, gmax);
  Bpwm = map(b, 0, 1023, 0, bmax);
  analogWrite(14, Rpwm);
  analogWrite(12, Gpwm);
  analogWrite(15, Bpwm);
  if(A){
   lcd.clear();
  Blynk.virtualWrite(5, bme.readHumidity());
  Serial.println(bme.readHumidity());
  Blynk.virtualWrite(6, bme.readPressure());
  Serial.println(bme.readPressure());
  Blynk.virtualWrite(0, bme.readTemperature());
  Serial.println(bme.readTemperature());
  lcd.print(0, 0, "T: ");
  lcd.print(3, 0, bme.readTemperature());
  lcd.print(8, 0, "°C");
  lcd.print(0, 1, "Pa: ");
  lcd.print(4, 1, bme.readPressure());
  A = !A;

  }
}
void ReadSensor() {
bme.takeForcedMeasurement();
Serial.println(r);
Serial.println(g);
A = !A;
}




1 Like

Instead of using the void loop() all wrong (for connection reliant processes like Blynk)… why not first try out this example and do some reading about the proper use of the void loop() with Blynk.

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

@Dmitriy I am sure there was one… if so, when did the official example of the zeRGBa widget get removed from the Sketch Builder?? If there never was… well… then… :blush:

Also… these values will never get passed beyond this function as they are assigned as Local variables and not Global…

https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/

Since you already defined them in the pre-setup… remove the int preceding each command in this function.

1 Like

Thanks for the help man, the weird thing is that it worked for me before, and i did a weird thing with a BLE project and everything went crazy, all my widgets in mi projects where getting values from other devices all of a sudden. And from there on I started a blynk chat for help and never got it, that i remember.

Yes, BLE is a whole other issue… but then I think it is still in beta anyhow.

How can i get the BLYNK_WRITE(V1) to pass the values?

nevermind

1 Like

I still cant get it to work, I changed the int from inside the BLYNK_WRYTE and it still doesnt pass the values, what i cant understand is why it doesnt work now but worked before

I would be surprised if it ever worked… what with multiple Blynk.virtualWrite() commands in the void loop() potentially trying to run hundreds or thousands of times a second :roll_eyes: (20ms is still a bit fast)

Not to mention the LCD Widget define running flat out… that should be in the pre-setup NOT in the void loop() :scream:

Perhaps it is time for you to look at some of those links provided. Nothing much else we can do for you until you fix the obvious issues :wink: