[Solved] Displaying data on the Terminal widget with button as the trigger

Hi,

i want to display data from my Wemos D1 into the Terminal widget window every time i push button in the app, so the trigger is from a virtual pin. But i got really difficult to make it shown right. When i push the button, the word comes many time on the window. As using delay will make this worst, i tried to use millis(); like Dmitriy said on this page : What to use instead of Delay() function for Arduino sketch?.
but still the outcome wasn’t better. So i tried to use simple time library like so :

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

WidgetTerminal terminal(V6);

const char* ssid = "FRITZ!Box 7330 SL";             //!!!!!!!!!!!!!!!!!!!!! modify this
const char* password = "xxxxxxxxxxxxxxxxxxxxx";                //!!!!!!!!!!!!!!!!!!!!!modify this

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";

SimpleTimer timer;
int button ;


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

 Blynk.begin(auth,ssid,password);

}

BLYNK_WRITE(V3) {          // button in the app, V3
   button = param.asInt();
   
}

void callback()
{
  terminal.println("please help me to put this text in the right way");
}

void loop() {
  Blynk.run();
  timer.run(); // Initiates SimpleTimer

if (button == HIGH){

       timer.setTimeout(750, callback);   // i already tried different delay time
      
   }
}

I also changed timer.setTimeout(750, callback); into restartTimer(timer.setTimeout(750, callback)) ;so the timer will be always restarted as long as the button is pressed. But the output is still so strange :sob:

Thank you!

@yusufaveroes I don’t see why any timers are needed for your requirement. What happens if you use this code?

BLYNK_WRITE(V1)   // button in Switch mode
{
  int Send2TerminalBtn = param.asInt();
  if (Send2TerminalBtn == 1) {
    terminal.print(F("Switch was turned ON"));
  }
  else
  {
    terminal.print(F("Switch was turned OFF"));
  }
  terminal.flush();
}

Edit: added terminal.flush().

@Costas

sorry, could you teach me how to delete this topic :dizzy_face:

i waste my day just searching arround about the solution. But just found the problem, i didn’t write the “flush” :weary:

thats why i need to push the button many time until the word shown with many copies…

and your code works fine with the “flush”

thanks for the answer :grin:

Topics shouldn’t be deleted as others are sure to have the same problem at some point in the future.