Hello, everyone, I hope you're safe at home and in good health.
I am doing a joint activity with MIT App Inventor, in which my concern lies. It turns out that I have to press a button on my App so that a message is displayed on the LCD and it rotates. The text should move only once and it finishes moving the text, it should disappear. At this point I can make the text move, however it will move again a few moments later.
I tried to create a flag to see if this could be a solution, but was not successful, could you help me with this problem?
I'm attaching my code right away (I'm programming in Arduino Mega 2560):
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int const led1=14, led2=15, led3=16, led4=17;
int data,value,flag=0;
String msg = "Ingenieria en Telecomunicaciones 2020";
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void serialEvent()
{
if(Serial.available()>0)
{
data=Serial.read();
switch (data)
{
case 'A': digitalWrite(led1, HIGH);
break;
case 'a': digitalWrite(led1, LOW);
break;
case 'B': digitalWrite(led2, HIGH);
break;
case 'b': digitalWrite(led2, LOW);
break;
case 'C': digitalWrite(led3, HIGH);
break;
case 'c': digitalWrite(led3, LOW);
break;
case 'D': digitalWrite(led4, HIGH);
break;
case 'd': digitalWrite(led4, LOW);
break;
case 'E': flag=1;
break;
default: break;
}
if(flag=1)
{
lcd.print(msg);
delay(200);
flag=0;
lcd.clear();
}
}
}
void loop()
{
lcd.scrollDisplayLeft();
delay(100);
}