[SOLVED] Check menu selection (preferably on a timer)

Is there a way to constantly check a menu widget selection on a timer? My menu widget allows you to select a room to read the min/max temp in that room for the past 24hrs. Right now, it works - but it only updates when I click into the menu and make a selection. This is because my menu code is in a BLYNK_WRITE function. It only changes when there’s a change in the menu. How do I check the menu selection every, say, second - or 5 seconds?

I’ve found a solution, y’all. I put a timer.set.Interval statement in the menu selection. Code below:

BLYNK_WRITE(V7) {
  switch (param.asInt())
  {
    case 1: //Mud Room
      //do nothing
      break;
    case 2: //Hallway
      //do nothing
      break;
    case 3: // Spa
      timer.setInterval(1000L, printMinMax);
      break;
    case 4: // Outside
      //do nothing
      break;
    default:
      lcd.print(0, 0, "24hr min: ");
      lcd.print(10, 0, "N/A");
      lcd.print(0, 1, "24hr max: ");
      lcd.print(10, 1, "N/A");
  }
}
1 Like

@Costas, this did work - for a bit. Did not work as a permanent solution. I have 4 devices talking to my blynk dashboard. When I select a room in my menu widget, the other timers on the other devices are still running. I tried using timer.disable(timerid), but I’m getting an error message. Here’s the error message: invalid conversion from 'void (*)()' to 'unsigned int' [-fpermissive].

Here is my code:

BLYNK_WRITE(V7) {
  switch (param.asInt())
  {
    case 1: //Mud Room
      timer.disable(printMinMax);
      break;
    case 2: //Hallway
      timer.enable(printMinMax);
      break;
    case 3: // Spa
      timer.disable(printMinMax);
      break;
    case 4: //Outside
      timer.disable(printMinMax);
      break;
    default:
      timer.disable(printMinMax);
      lcd.print(0, 0, "24hr min: ");
      lcd.print(10, 0, "N/A");
      lcd.print(0, 1, "24hr max: ");
      lcd.print(10, 1, "N/A");
  }
}

And here is my setup:

void setup() {
  pinMode(connectionLED, OUTPUT);
  digitalWrite(connectionLED, LOW);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1011L, readTemp);
  timer.setInterval(1520L, checkConnection);
  timer.setInterval(86400000L, resetMinMax);
  timer.setInterval(1000L, printMinMax);
  Serial.begin(115200);
  DS18B20.begin();
  notified = false;
  lcd.clear();
}

Any idea why this is not working?

Some of the “SimplerTimer” (aka Blynk Timer) functions have to be declared as integers and the timers can then be deleted / paused etc. Check out Arduino page but it’s not as clear as it should be.

I figured it out. It’s not that clear. But basically, in my globals, I declared int tempMinMax. Then, in setup, I have:

tempMinMax = timer.setInterval(10000L, printMinMax);
timer.disable(tempMinMax);

My Blynk_Write function looks like this:

BLYNK_WRITE(V7) {
  switch (param.asInt())
  {
    case 1: //Mud Room
      timer.disable(tempMinMax);
      break;
    case 2: //Hallway
      timer.enable(tempMinMax);
      break;
    case 3: // Spa
      timer.disable(tempMinMax);
      break;
    case 4: //Outside
      timer.disable(tempMinMax);
      break;
    default:
      timer.disable(tempMinMax);
      lcd.print(0, 0, "24hr min: ");
      lcd.print(10, 0, "N/A");
      lcd.print(0, 1, "24hr max: ");
      lcd.print(10, 1, "N/A");
  }
}

And my timed function is below:

void printMinMax() {
  lcd.print(0, 0, "24hr min: ");
  lcd.print(10, 0, tempMIN);
  lcd.print(0, 1, "24hr max: ");
  lcd.print(10, 1, tempMAX);
}

I basically have the same thing on the other devices with my timer.enables/disables offset so that I can select each room without them interfering with each other. Working like a charm! (so far…) Thanks for the input @Costas!