Hi javier
There are very few times when a delay can be used safely - the reason being that it blocks everything. Here is an example Sketch showing how to use elapsed milliseconds:
//#include<SoftwareSerial.h>
//vars
unsigned int igUpdateTime;
char val[];
void setup()
{
Serial.begin(9600);
igUpdateTime = millis();
}
void loop()
{
//Excute loop every 10 seconds
if((millis() - igUpdateTime) > 10000)
{
igUpdateTime = millis();
if (Serial.available() > 0)
{
//Read Data From App
val = Serial.read();
switch (val) {
case '1':
digitalWrite(led1, HIGH);
break;
case '2':
digitalWrite(led1, LOW);
break;
case '3':
digitalWrite(led2, HIGH);
break;
case '4':
digitalWrite(led2, LOW);
break;
}
}
}
}