Menu widget not working for certain menu items

Hey all,

I’m trying to use a menu to set sliders to specific values. I.e. you select item 1 and the sliders move to value based on your code. Here is my current code:

BLYNK_WRITE(V24) {
  switch (param.asInt()) {
    case 1: // Custom
      Blynk.virtualWrite(V0, 65);  //T1
      Blynk.virtualWrite(V1, 65);  //T2
      Blynk.virtualWrite(V2, 65);  //T3
      Blynk.virtualWrite(V3, 65);  //T4
      Blynk.virtualWrite(V4, 0);  //t1
      Blynk.virtualWrite(V5, 0);  //t2
      Blynk.virtualWrite(V6, 0);  //t3
      Blynk.virtualWrite(V7, 0);  //t4
      Blynk.virtualWrite(V23, 0);  //bt
      break;
    case 2: // IPA
      Blynk.virtualWrite(V0, 148);  //T1
      Blynk.virtualWrite(V1, 172);  //T2
      Blynk.virtualWrite(V2, 65);  //T3
      Blynk.virtualWrite(V3, 65);  //T4
      Blynk.virtualWrite(V4, 60);  //t1
      Blynk.virtualWrite(V5, 10);  //t2
      Blynk.virtualWrite(V6, 0);  //t3
      Blynk.virtualWrite(V7, 0);  //t4
      Blynk.virtualWrite(V23, 120);  //bt
      break;
    case 3: // Stout
      Blynk.virtualWrite(V0, 130);  //T1
      Blynk.virtualWrite(V1, 145);  //T2
      Blynk.virtualWrite(V2, 65);  //T3
      Blynk.virtualWrite(V3, 65);  //T4
      Blynk.virtualWrite(V4, 30);  //t1
      Blynk.virtualWrite(V5, 30);  //t2
      Blynk.virtualWrite(V6, 0);  //t3
      Blynk.virtualWrite(V7, 0);  //t4
      Blynk.virtualWrite(V23, 60);  //bt
      break;
    case 4: // Lager
      Blynk.virtualWrite(V0, 130);  //T1
      Blynk.virtualWrite(V1, 148);  //T2
      Blynk.virtualWrite(V2, 172);  //T3
      Blynk.virtualWrite(V3, 65);  //T4
      Blynk.virtualWrite(V4, 40);  //t1
      Blynk.virtualWrite(V5, 20);  //t2
      Blynk.virtualWrite(V6, 10);  //t3
      Blynk.virtualWrite(V7, 0);  //t4
      Blynk.virtualWrite(V23, 60);  //bt
    case 5: // Saison
      Blynk.virtualWrite(V0, 128);  //T1
      Blynk.virtualWrite(V1, 65);  //T2
      Blynk.virtualWrite(V2, 65);  //T3
      Blynk.virtualWrite(V3, 65);  //T4
      Blynk.virtualWrite(V4, 60);  //t1
      Blynk.virtualWrite(V5, 0);  //t2
      Blynk.virtualWrite(V6, 0);  //t3
      Blynk.virtualWrite(V7, 0);  //t4
      Blynk.virtualWrite(V23, 60);  //bt
  }
}

The first three menu items work fine. But when I get to the 4th one, the sliders move and then reset back to 65 and 0 (65 is at the bottom of the range for those sliders). Anybody have an idea as to why this is happening?

Maybe it’s just too many values to write at once? @Costas any idea here?

I never have more than 3 or 4 consecutive virtualWrite’s together and have all frequency widgets set to PUSH.

I kind of need to have all of those virtualWrite’s there. How could I achieve the same effect without have them all together?

Do 3 virtualWrites and do the rest with SimpleTimer.

As in set a time delay between the first 3 virtualWrites and the next three?

I kind of gave up on the menu as it’s not needed (would be nice but not totally necessary). However, I’m trying to create this project and I’m running into problems all over. I’m thinking I am structuring my code terribly. Could I post the whole thing and go through it with you @Costas? I understand if you don’t have time to do so - it is asking a lot. I could also provide a process flow if needed. Again, understandable if you’re too busy to do so.

Nevermind @Costas, I’ve worked out some kinks. However, I have one major problem. I have a while loop within a BLYNK_WRITE function. It’s supposed to work like so: While the button is high, run code. While it is not high, turn some stuff off and go back to loop. However, it seems to be stuck in the while loop. My button is set to be a switch, not a push. So it should always be high (== 1) while it’s switched on, right? Here’s the code:

BLYNK_WRITE(V8) {
  rampButton = param.asInt();
  Setpoint = rampTemp;
  while  (rampButton == 1) {
    sensors1.requestTemperatures();
    sensors2.requestTemperatures();
    float Inlet_temp = sensors1.getTempFByIndex(0);
    float Outlet_temp = sensors2.getTempFByIndex(0);

    Blynk.virtualWrite(V19, Inlet_temp);
    Blynk.virtualWrite(V20, Outlet_temp);

    digitalWrite(v1, LOW);
    Blynk.virtualWrite(V12, ON);
    digitalWrite(v2, LOW);
    Blynk.virtualWrite(V13, ON);
    digitalWrite(pump, LOW);
    Blynk.virtualWrite(V16, ON);

    Input = Inlet_temp;
    double gap = abs(Setpoint - Input);
    if (gap < 10) {
      myPID.SetTunings(consKp, consKi, consKd);
    }
    else {
      myPID.SetTunings(aggKp, aggKi, aggKd);
    }
    myPID.Compute();
    unsigned long now = millis();
    if (now - windowStartTime > WindowSize) {
      windowStartTime += WindowSize;
    }
    if (Output > now - windowStartTime) {
      digitalWrite(steam, HIGH);
      digitalWrite(steamLight, LOW);
      Blynk.virtualWrite(V17, ON);
    }
    else {
      digitalWrite(steam, LOW);
      digitalWrite(steamLight, HIGH);
      Blynk.virtualWrite(V17, OFF);
    }
    Blynk.virtualWrite(V21, Setpoint);
    Blynk.virtualWrite(V22, (Setpoint - Outlet_temp));
  }
  digitalWrite(pump, HIGH);
  digitalWrite(v1, HIGH);
  digitalWrite(pump, HIGH);
  Blynk.virtualWrite(V12, OFF);
  Blynk.virtualWrite(V13, OFF);
  Blynk.virtualWrite(V16, OFF);
  Blynk.virtualWrite(V17, OFF);
  loop();
}

Okay so I’ve been working on it for a while and I still can’t figure it out. I cannot, for the life of me, figure this out. Here’ my latest rendition:

BLYNK_WRITE(V8) {
  rampButton = param.asInt();
  Setpoint = rampTemp;
  sensors1.requestTemperatures();
  sensors2.requestTemperatures();
  float Inlet_temp = sensors1.getTempFByIndex(0);
  float Outlet_temp = sensors2.getTempFByIndex(0);
  if  (rampButton == 1 && (Outlet_temp < rampTemp)) {
    sensors1.requestTemperatures();
    sensors2.requestTemperatures();
    float Inlet_temp = sensors1.getTempFByIndex(0);
    float Outlet_temp = sensors2.getTempFByIndex(0);
    Blynk.virtualWrite(V19, Inlet_temp);
    Blynk.virtualWrite(V20, Outlet_temp);
    digitalWrite(v1, LOW);
    Blynk.virtualWrite(V12, ON);
    digitalWrite(v2, LOW);
    Blynk.virtualWrite(V13, ON);
    digitalWrite(pump, LOW);
    Blynk.virtualWrite(V16, ON);
    Input = Inlet_temp;
    double gap = abs(Setpoint - Input);
    if (gap < 10) {
      myPID.SetTunings(consKp, consKi, consKd);
    }
    else {
      myPID.SetTunings(aggKp, aggKi, aggKd);
    }
    myPID.Compute();
    unsigned long now = millis();
    if (now - windowStartTime > WindowSize) {
      windowStartTime += WindowSize;
    }
    if (Output > now - windowStartTime) {
      digitalWrite(steam, HIGH);
      digitalWrite(steamLight, LOW);
      Blynk.virtualWrite(V17, ON);
    }
    else {
      digitalWrite(steam, LOW);
      digitalWrite(steamLight, HIGH);
      Blynk.virtualWrite(V17, OFF);
    }
    Blynk.virtualWrite(V21, Setpoint);
    Blynk.virtualWrite(V22, (Setpoint - Outlet_temp));
  }
  else {
    loop();
  }
}

@jeebsinc I think your code will improve if you learn how to use SimpleTimer http://playground.arduino.cc/Code/SimpleTimer