BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Terminal infinite loop

#1

Hello All
First of all, I am very new to using arduino and blynk.
I have a problem with the terminal widget and I couldn’t find a similar topic maybe because it might be a stupid question.
However, here is my problem. I want Blynk to send a message on terminal. I am working on a laser tripwire and want it to write “Alarm!” when the alarm is triggered.
Before including the terminal code into my program I was trying some stuff with the widget but I have the problem that the message gets send infinitly. For this experiment I have 2 LEDs and I want terminal to just send the message once and not repeat it every loop. How can I fix this?

Edit: I know I can use notify for this case, but then I would have the same problem having never ending notifications.
Why I need terminal specificaly is that I want it to give a message like “Alarm! Type in Password here to deactivate”

void test()
{
    int digitalValue = digitalRead(greenled);
    if (digitalValue == LOW) {
    digitalWrite(redled,HIGH);
    terminal.println(F("Alarm!"));
    terminal.flush();}
    else {
    digitalWrite(redled,LOW);}
}
0 Likes

#2

Flags and/or counters

int flag = 0;

Check a flag setting… and if not set if (flag == 0) {}

Then do something and then set a flag flag = 1; to prevent further doings of something.

For example using Boolean Operators - https://www.arduino.cc/reference/en/

if (digitalValue == LOW && flag == 0) {
0 Likes

#3

So would it be something like:

int flag = 0

void test()
{
    int digitalValue = digitalRead(greenled);
    if (digitalValue == LOW) {
    digitalWrite(redled,HIGH);
       if (flag == 0){
       terminal.println(F("Alarm!"));
       terminal.flush();
       flag = 1;}
    else {
    digitalWrite(redled,LOW);}
}

Edit: Just tried and Great! it worked like this! Thanks for the fast help.

0 Likes

#4

Then remember to change it back to 0 somewhere in your code (reset button, timer, etc.) if you ever want the alarm to go off again.

0 Likes