So the first level works fine. The if is executed every x seconds. Every x seconds i want the Trigger to be HIGH for y seconds (here 500ms). But how can i do this within the first condition without using delay?
If you use a variable to represent the current state (two possible values), then use a switch statement to determine the
current state in the loop(), something a bit like:
int state ;
void setup ()
{
state = 0 ;
TriggerTimer = millis () ;
// plus other initialization code.
}
void loop ()
{
switch (state)
{
case 0:
if (millis() - TriggerTimer > xDelay * 1000)
{
digitalWrite (Trigger, HIGH) ;
TriggerTimer = millis () ;
state = 1 ;
}
break ;
case 1:
if (millis() - TriggerTimer > yDelay * 1000)
{
digitalWrite (Trigger, LOW) ;
TriggerTimer = millis () ;
state = 0 ;
}
break ;
}
// plus any other stuff ....
}