Error 138 when compiling code in arduino

Hello guys

I’m riding a code with several options utilizand the widget menu.
already utizo cógido with a simple menu and have no problems. but this new code some errors are appearing.

I will post the code that is giving problem and the error then.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SimpleTimer.h>
#define ONE_WIRE_BUS 7
#define COOLER 4
#define LA 2
#define LB 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "d45054bf012e46b49f29314f95288464";

SimpleTimer timer;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  sensors.begin();
  pinMode(COOLER, OUTPUT);
  digitalWrite(COOLER, LOW);
  pinMode(LA, OUTPUT);
  pinMode(LB, OUTPUT);
  digitalWrite(LA, HIGH);
  digitalWrite(LB, HIGH);
  timer.setInterval(3000, readTemp);
  // You can also specify server.
  // For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
  //Blynk.begin(auth, "your_server.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8888);
}
BLYNK_WRITE(2) //entre parenteses o número do pino virtual do menu de seleção
{
  switch (param.asInt())
  {
    case 1: { //Seleciona o MODO AUTOMÁTICO

        BLYNK_WRITE(3) //entre parenteses o número do pino virtual que vai no timer do Led Azul
        {
          int i = param.asInt ();
          if (i == 1)
          {
            digitalWrite (LA, LOW);
            Blynk.virtualWrite(6, 255);
          }
          else if (i == 0)
          {
            digitalWrite (LA, HIGH);
            Blynk.virtualWrite(6, 0);
          }
        }
        BLYNK_WRITE(4) //entre parenteses o número do pino virtual que vai no timer do Led Branco
        {
          int i = param.asInt ();
          if (i == 1)
          {
            digitalWrite (LB, LOW);
            Blynk.virtualWrite(7, 255);
          }
          else if (i == 0)
          {
            digitalWrite (LB, HIGH);
            Blynk.virtualWrite(7, 0);
          }
        }
        break;
      }

    case 5: {
        BLYNK_WRITE(5) //entre parenteses o número do pino virtual que vai no controle independente do LED BRANCO
        {
          switch (param.asInt())
          {
            case 1: {
                digitalWrite (LB, LOW);
                Blynk.virtualWrite(7, 255);
                break;
              }
            case 2: {
                digitalWrite (LB, HIGH);
                Blynk.virtualWrite(7, 0);
                break;
              }
            default: {   }
          }
        }
        BLYNK_WRITE(8) //entre parenteses o número do pino virtual que vai no controle independente do LED AZUL
        {
          switch (param.asInt())
          {
            case 1: {
                digitalWrite (LA, LOW);
                Blynk.virtualWrite(6, 255);
                break;
              }
            case 2: {
                digitalWrite (LA, HIGH);
                Blynk.virtualWrite(6, 0);
                break;
              }
            default: {   }
          }
        }
        break;
      }
    default: { }
  }
}

void readTemp()
{
  sensors.requestTemperatures();
  float floatTempC = sensors.getTempCByIndex(0);
  char t_buffer[15];
  dtostrf(floatTempC, 8, 9, t_buffer);
  Blynk.virtualWrite(0, t_buffer);
  if (floatTempC >= 27.5)
  {
    digitalWrite(COOLER, LOW); //LIGA COOLER
    Blynk.virtualWrite(1, 255);
  }
  else if (floatTempC <= 27)
  {
    digitalWrite(COOLER, HIGH); //DESLIGA COOLER
    Blynk.virtualWrite(1, 0);
  }
}
void loop()
{
  Blynk.run();
  timer.run();
}

@lucasAlexey what made you think you could put one BLYNK_WRITE() function inside another BLYNK_WRITE() function?

I suggest you get the status of the required virtual pins before entering the switch statement.

I developed the code based on the menu that I want to create for each item of the menu I wrote the code in the “due” place. but from what I saw will not fuincionar. It is to give me an example or help how to do?

@Costas

I rewrote the code … but I’m not getting results, I want is the following:

Main Menu - lights work in the auto with the timer.
Manual menu - can turn on and off lights, control intensity.

the code is so far managed to load the arduino but did not work:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SimpleTimer.h>
#define ONE_WIRE_BUS 7
#define COOLER 4
#define LA 2
#define LB 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "d45054bf012e46b49f29314f95288464";

SimpleTimer timer;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  sensors.begin();
  pinMode(COOLER, OUTPUT);
  digitalWrite(COOLER, LOW);
  pinMode(LA, OUTPUT);
  pinMode(LB, OUTPUT);
  digitalWrite(LA, HIGH);
  digitalWrite(LB, HIGH);
  timer.setInterval(3000, readTemp);
  // You can also specify server.
  // For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
  //Blynk.begin(auth, "your_server.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8888);
}


int hla;
int hlb;
int bllb;
int bdlb;
int blla;
int bdla;



BLYNK_WRITE(3)  //entre parenteses o número do pino virtual que vai no timer do Led Azul - LIGA/DESL O LED AZUL NA HORA PROGRAMADA - ATRIBUI 1 OU 0 A VARIÁVEL
{  
  hla = param.asInt ();
  
}

BLYNK_WRITE(4)  //entre parenteses o número do pino virtual que vai no timer do Led Branco - LIGA/DESL O LED BRACO NA HORA PROGRAMADA - ATRIBUI 1 OU 0 A VARIÁVEL
  {
  hlb = param.asInt ();
}



BLYNK_WRITE(5) //entre parenteses o número do pino virtual que vai no controle independente do LED BRANCO - PERMITE LIGAR E DESLIGAR O LED BRANCO A QUALQUER MOMENTO
{
  switch (param.asInt())
  {
    case 1: { //LIGA LED BRANCO
        bllb = 1;
        break;
      }
    case 2: { //DESLIGA LED BRANCO
        bdlb = 1;
        break;
      }
    default: {}
  }
}

BLYNK_WRITE(8) //entre parenteses o número do pino virtual que vai no controle independente do LED AZUL - PERMITE LIGAR E DESLIGAR O LED AZUL A QUALQUER MOMENTO
{
  switch (param.asInt())
  {
    case 1: { //LIGA LED AZUL
        blla = 1;
        break;
      }
    case 2: { //DESLIGA LED AZUL
        bdla = 1;
        break;
      }
    default: {}
  }
}

BLYNK_WRITE(2) //entre parenteses o número do pino virtual do menu de seleção
{
  switch (param.asInt())
  {
    case 1: { //Seleciona o MODO AUTOMÁTICO

        if (hla == 1)
        {
          digitalWrite (LA, LOW);
          Blynk.virtualWrite(6, 255);
          Blynk.virtualWrite(9, 255);
        }
        else if (hla == 0)
        {
          digitalWrite (LA, HIGH);
          Blynk.virtualWrite(6, 0);
          Blynk.virtualWrite(9, 0);
        }

        if (hlb == 1)
        {
          digitalWrite (LB, LOW);
          Blynk.virtualWrite(7, 255);
          Blynk.virtualWrite(10, 255);
        }
        else if (hlb == 0)
        {
          digitalWrite (LB, HIGH);
          Blynk.virtualWrite(7, 0);
          Blynk.virtualWrite(10, 0);
        }
        break;
      }

    case 5: { //Seleciona o MODO INDEPENDENTE
        if (bllb == 1)
        {
          digitalWrite (LB, LOW);
          Blynk.virtualWrite(7, 255);
          Blynk.virtualWrite(10, 255);
        }
        if (bdlb == 1)
        {
          digitalWrite (LB, HIGH);
          Blynk.virtualWrite(7, 0);
          Blynk.virtualWrite(10, 0);
        }

        if (blla == 1)
        {
          digitalWrite (LA, LOW);
          Blynk.virtualWrite(6, 255);
          Blynk.virtualWrite(9, 255);
        }
        if (bdla == 1)
        {
          digitalWrite (LA, HIGH);
          Blynk.virtualWrite(6, 0);
          Blynk.virtualWrite(9, 0);
        }
        break;
      }
    default: { }
  }
}


void readTemp()
{
  sensors.requestTemperatures();
  float floatTempC = sensors.getTempCByIndex(0);
  char t_buffer[15];
  dtostrf(floatTempC, 8, 9, t_buffer);
  Blynk.virtualWrite(0, t_buffer);
  if (floatTempC >= 27.5)
  {
    digitalWrite(COOLER, LOW); //LIGA COOLER
    Blynk.virtualWrite(1, 255);
  }
  else if (floatTempC <= 27)
  {
    digitalWrite(COOLER, HIGH); //DESLIGA COOLER
    Blynk.virtualWrite(1, 0);
  }
}
void loop()
{
  Blynk.run();
  timer.run();
}

@lucasAlexey to help me debug your code and to improve your understanding of the sketch when you look back at it in a few months time can you make the following changes:

'1. Move BLYNK_WRITE(2) before BLYNK_WRITE(3) (keep the functions in numerical order)
'2. At the top of the sketch add comments stating which widgets you are using against which pins
'3. Comment your variables when you define them.
'4. Add comments in English alongside your native language
'5 Would recommend in future you use longer variable names (not LA, LB etc)

Then if you could be a little clearer on what is working and specifically what is not.

When I search your sketch for “sync” it doesn’t appear once. I expect sync to appear in most sketches of your type. Read the docs for sync.

Many Blynk sketches show a line like this:

Blynk.begin(auth);

but I like to see it followed by this for almost all sketches:

while (Blynk.connect() == false) { 
  // Wait until connected
}