Code troubleshooting

Not sure if this is right place to post as I dont know whether my issue is in my programming or setup in my T3 controller (I’m a newbie at this) but here goes. I just completed a program that is basically a selection program (Hopefully for an old vending machine). I am trying to read my #1 input (IN1). if it gets activated momentarily then the program will wait 3 minutes for any of the other inputs (IN2-10) to be toggled or go back to waiting for another toggle of IN1. When that happens the corresponding output (OUT2-10) needs to turn on for 5 seconds. Anyway my code compiles and loads but I cannot get my outputs to light when testing (Just watching the LEDs)? My inputs light when toggled in software or physically jumpered but no output? My outputs are set to auto and in a off/on range (Tried others also). What am I missing? Here is my code:

10 REM Selection Process
20 REM Wait for Input 1 to be pressed
30 IF IN1 THEN GOTO 40
40 REM Input 1 has been pressed, wait for other inputs
50 WAIT(180000)
60 IF IN2 THEN GOTO 160
70 IF IN3 THEN GOTO 180
80 IF IN4 THEN GOTO 200
90 IF IN5 THEN GOTO 220
100 IF IN6 THEN GOTO 240
110 IF IN7 THEN GOTO 260
120 IF IN8 THEN GOTO 280
130 IF IN9 THEN GOTO 300
140 IF IN10 THEN GOTO 320
150 REM No other inputs have been pressed, go back to waiting for Input 1
160 REM IN2 has been pressed, activate OUT2 for 5 seconds
170 OUT2 = 1
180 WAIT(5000)
190 OUT2 = 0
200 REM IN3 has been pressed, activate OUT3 for 5 seconds
210 OUT3 = 1
220 WAIT(5000)
230 OUT3 = 0
240 REM IN4 has been pressed, activate OUT4 for 5 seconds
250 OUT4 = 1
260 WAIT(5000)
270 OUT4 = 0
280 REM IN5 has been pressed, activate OUT5 for 5 seconds
290 OUT5 = 1
300 WAIT(5000)
310 OUT5 = 0
320 REM IN6 has been pressed, activate OUT6 for 5 seconds
330 OUT6 = 1
340 WAIT(5000)
350 OUT6 = 0
370 REM IN7 has been pressed, activate OUT7 for 5 seconds
380 OUT7 = 1
390 WAIT(5000)
400 OUT7 = 0
410 REM IN8 has been pressed, activate OUT8 for 5 seconds
420 OUT8 = 1
430 WAIT(5000)
440 OUT8 = 0
450 REM IN9 has been pressed, activate OUT9 for 5 seconds
460 OUT9 = 1
470 WAIT(5000)
480 OUT9 = 0
490 REM IN10 has been pressed, activate OUT10 for 5 seconds
500 OUT10 = 1
510 WAIT(5000)
520 OUT10 = 0
530 REM Done, go back to waiting for Input 1
540 GOTO 20

You have an infinite loop in the program which will cause trouble. The way the controller works is to cache the state of the output till the program exits. After that the output state is written to the hardware and the program restarts itself automatically. Since your code never exits, the cache never gets written out to the hardware. You can learn more about this by searching the forum for ‘infinite loop’ and ‘goto’.

Also, pro tip: try to avoid gotos, just use a variable to store the state of some complex logic and then use that variable along with some other separate logic to deal with the outputs. This way you can see the state of the variable on your graphics displays and so on for better troubleshooting.

Thanks. I’ve tried what you’ve said but either get syntax errors or just won’t enable the outputs so i’m obviously sucking at this controllers quirks. I can do well with trane cpl and pcl but for some reason just pulling my hair out. . I’m gonna read again and see what i’m missing. If not ill just use a different controller. Is there any sample codes I can download to study? particularly on inputs and outputs?

I just found some examples others have posted. i’ll study and see what i’m doing wrong

There’s plenty of examples on the forum here. If you don’t see one that fits your application you can write it up and post on a new thread. I will respond with a detailed program.

1 Like

Thanks. Thats what i’ll do since I can’t seem to get anything I write to work fully.