Verbose menu widget code

Is there a clearer, less verbose way of coding this? My project uses a lot of menus with 20+ items and the code is really repetitive. My first thought would be to loop through building cases particularly when the values from the menu are as with this one multiples of 5 from 0-100 inclusive, but that is a constexpr (I think) and I can’t take that approach. I’d like to end up with something that I could show to an(other) noob who could see easily what is going on and use it. Many thanks, James.

BLYNK_WRITE(V11) { //target basking humidity menu widget
switch (param.asInt())
{
case 1:
  {
    Serial.println("Target Basking Humidity set at 5");
    int targetBaskingHumidity = 5;
    Blynk.virtualWrite(V18, targetBaskingHumidity);
    break;
  }
case 2:
  {
    Serial.println("Target Basking Humidity set at 10");
    int targetBaskingHumidity = 10;
    Blynk.virtualWrite(V18, targetBaskingHumidity);
    break;
  }

Hello. Yes, it could be simplified. Pseudo code :

int targetBaskingHumidity;
switch (param.asInt())
{
case 1:
  {
    targetBaskingHumidity = 5;
    break;
  }
case 2:
  {
    targetBaskingHumidity = 10;
    break;
  }

 Serial.println(String("Target Basking Humidity set at ") + targetBaskingHumidity);
 Blynk.virtualWrite(V18, targetBaskingHumidity);
1 Like

Many thanks!

use a slider?

int targetBaskingHumidity;

BLYNK_WRITE(V11) //slider with 5-100 range
{
  targetBaskingHumidity = (param.asInt);
  Blynk.virtualWrite(V18, targetBaskingHumidity);
  Serial.println(String("Target Basking Humidity set at ") + targetBaskingHumidity);
 }

I have considered this, but it is mission critical that this slider doesn’t get moved even a fraction by accident, and I believe that this is less likely to happen using a menu, if nothing else because it requires two touch actions instead of one. Good suggestion though in most other cases, so for anyone reading this and wondering the same thing… What Dave said lol!