How to settup a Blynk menu?

Well hello, internet,
I wanna use the menu in blynk, but I can’t. for example as a simple sketch:
When a user selects the 1st item it will blink an LED for a short duration, and when the 2nd item is selected it will blink the previous LED for a long duration.
Is this possible?
I’m using NODEMCU D1 mini
Thanks in advance.

Obviously it’s possible, but maybe not with your current skill set.

Take a look at this sketch:
https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FMenu

And do a google search for the Ticker library.
Combine the two and you’ll valve what you need, and you’ll have learned something along the way.

Pete.

Thanks for your reply,
I’ve used the official menu sketch already to make what I described, but all in vain.
I intended to do something like goto or something else.
I’ll google the Ticker library, and get back to you as soon as possible.

Good luck with that!

I’ve never felt the need to use a goto in C++, although I guess there are cases where it is a valuable tool.

The problem I have with goto is that it reminds me too much of the awful GOTO statement in BASIC, which is something I haven’t felt the need to use for at least the past 35 years.

Pete.

2 Likes

WOW 35 years at least!!!, Is it an annoying tool that you’ve been a long time don’t use it?
I’m a beginner at C language, so all I could really think of at that moment is goto.

There no need to direct your program flow anywhere, so go to or calling a function are unnecessary.
This is part of the code from the sketch builder menu example, edited to show where the extra code would go…

BLYNK_WRITE(V1) {
  switch (param.asInt())
  {
    case 1: // Item 1
      Serial.println("Item 1 selected");
       // add the lines of code to blink the LED for a short duration here
      break;
    case 2: // Item 2
      Serial.println("Item 2 selected");
      // add the lines of code to blink the LED for a longer duration here  
      break;

Pete.

Sorry for my poor response time.
I’ve followed your instructions, and built this sketch:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetLCD lcd(V2);
BLYNK_WRITE(V1) {
  switch (param.asInt())
  {
    case 1: // Item 1
      Serial.println("Long Duration");
      lcd.clear(); //Use it to clear the LCD Widget
      lcd.print(0, 0, "Long Duration");
      Serial.println("Long Duration");
      digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
      // but actually the LED is on; this is because
      // it is active low on the NODEMCU)
      delay(200);                      // Wait for a second
      digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
      delay(300);
      break;
    case 2: // Item 2
      Serial.println("Short Duration");
      Serial.println("Short Duration");
      lcd.clear(); //Use it to clear the LCD Widget
      lcd.print(0, 0, "Short Duration");
      Serial.println("Short Duration");
      digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
      // but actually the LED is on; this is because
      // it is active low on the NODEMCU)
      delay(2000);                      // Wait for a second
      digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
      delay(3000);
      break;
    default:
      Serial.println("Unknown item selected");
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
}

After a successful upload, I selected one of the items and I’ve got nothing.
Any suggestions

No PinMode declaration and no use of the Ticker library (you can’t use delays like this with Blynk).

Pete

Thanks for the reminder.
GREAT!! my code works fine.
Thanks for the support.
I made the sketch again, and this is my code for who is intrested:

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Ticker.h>




// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SSID";
char pass[] = "Pass";

Ticker blinker;
void changeState()
{
  digitalWrite(LED_BUILTIN, !(digitalRead(LED_BUILTIN)));  //Invert Current State of LED  
}


WidgetLCD lcd(V2);

BLYNK_WRITE(V1) {
 
  switch (param.asInt())
  {
    case 1: // Item 1
      Serial.println("Long Duration");
      lcd.clear(); //Use it to clear the LCD Widget
      lcd.print(0, 0, "Long Duration");
      blinker.attach(1, changeState); //time in seconds, for ms use attach_ms
      break;
    
    case 2: // Item 2
      Serial.println("Short Duration");
      Serial.println("Short Duration");
      lcd.clear(); //Use it to clear the LCD Widget
      lcd.print(0, 0, "Short Duration");
      blinker.attach(.2, changeState); //Use attach_ms if you need time in ms
      break;
      
    default:
      Serial.println("Unknown item selected");
  }
}

void setup()
{
  
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  
  pinMode(LED_BUILTIN, OUTPUT);
 
}

void loop()
{

  Blynk.run();
}