Hello! I want to make a simple program that turns on all the LEDs on a digital output with a delay of one second, but I’m having problems creating the delay, in the attached pictures I’ll show you how I tried to do it.
Hello, I had an issue similar to yours recently where I meant to add a structured text file but I added an automation basic file by mistake. It looks like yours is an Automation Basic file based on the error and green semicolons. The END_IF is structured text whereas ENDIF is used in Automation Basic.
Here is an example you can use to understand how to use timers.
The program below will turn on LEDs with a delay of one second between each, assuming you have multiple LEDs connected to digital outputs.
//Declaration
VAR
DO_1 : BOOL;
DO_2 : BOOL;
DO_3 : BOOL;
timer_1 : TON;
timer_2 : TON;
timer_3 : TON;
END_VAR
PROGRAM _INIT
//Set timers
Timer_1(IN := NOT Timer_1.Q, PT := T#1s); // 1 second delay for LED1
Timer_2(IN := Timer_1.Q AND NOT Timer_2.Q, PT := T#1s); // 1 second delay for LED2
Timer_3(IN := Timer_2.Q AND NOT Timer_3.Q, PT := T#1s); // 1 second delay for LED3
// Output
IF Timer_1.Q THEN
DO_1 := TRUE;
END_IF;
IF Timer_2.Q THEN
DO_2 := TRUE;
END_IF;
IF Timer_3.Q THEN
DO_3 := TRUE;
END_IF;
PROGRAM _EXIT
You can adapt the program by adding more outputs (LEDs), and by changing the condition in the IN := … of the timer. You can change the time delay in the PT := …
//Set timers
Timer_1(IN := NOT Timer_1.Q, PT := T#1s); // 1 second delay for LED1
Timer_2(IN := Timer_1.Q AND NOT Timer_2.Q, PT := T#1s); // 1 second delay for LED2
Timer_3(IN := Timer_2.Q AND NOT Timer_3.Q, PT := T#1s); // 1 second delay for LED3
// Output
IF Timer_1.Q THEN
DO_1 := TRUE;
ENDIF;
IF Timer_2.Q THEN
DO_2 := TRUE;
ENDIF;
IF Timer_3.Q THEN
DO_3 := TRUE;
ENDIF;