Learning Control Basic: timers & momentary switches

So i have a lot of issues trying to test my code out that I’m not sure where the problem lies. I am try to make a selection process that when one input is toggled (IN1) that the user has 3 minutes to select one of 9 inputs (IN2-10) which then turns on a corresponding output (OUT2-10). I’ve went through about 15 different iterations trying to get the syntax right so it loads and to get it to work.This shortened code just to figure the controller out doesn’t work consistently either? This when first loaded would enable the outputs almost instantly and do the 5 second delay when turning off. Now they seem to delay 5 seconds when turning on and I’ve changed nothing (Saved every code before changing) ,Also a few times i’ve enabled IN1 and IN2 and nothing happens? The other puzzling thing is my VAR1 never changes when viewing in T3000 BAS? I’m not even trying to do my actual project at this point. I am just trying to understand how to work this thing. I did finally figure out the hard way that for time you have to use the 00:00:05 format over 5000 ms (Which may have been the issue in my earlier codes that i’ll revisit) . Anyway here is my basic code that sometimes works but waits to even start the ouputs unless IN1 and VAR1 are held for 5 seconds (VAR1 never goes to 1 when viewing even with IN1 and IN2 on) :
10 IF+ IN1 THEN VAR1 = 1
20 REM
60 IF+ IN2 AND VAR1 = 1 THEN START OUT2
70 IF+ IN3 AND VAR1 = 1 THEN START OUT3
80 WAIT 00:00:05
90 STOP OUT2
100 STOP OUT3
110 VAR1 = 0
120 END

Now i’m convinced it is something with my controller or how i am doing it in T3000 software? I had the following code which was working as far as turning on my outputs even though it was not correct I saved it anyway. But now when i load it nothing happens when i toggled IN! on with IN2 or 3?
10 IF+ IN1 THEN VAR1 = 1 VAR3 = TIME
20 REM
30 IF VAR1 = 1 THEN GOTO 40
40 IF+ IN2 THEN START OUT2 VAR2 = TIME
50 IF+ IN3 THEN START OUT3 VAR2 = TIME
60 IF VAR2 > 0 AND VAR2 + 5 < TIME THEN VAR1 = 0 STOP OUT2 STOP OUT3
70 IF VAR1 = 1 AND VAR3 + 00:03:00 < TIME THEN VAR1 = 0
80 GOTO 10

SO i just tried this simple code and could not get my outputs to light. Do I need to clear or something each time I load code and thats why mines screwing up? anyway this code wont even work if IN1 and IN2 are turned on together. :
10 IF IN1 = 1 THEN VAR1 = 1
30 IF IN2 = 1 AND VAR1 = 1 THEN START OUT1
50 END
in fact I just tried this and no go: 10 IF+ IN1 THEN OUT1 = 1 or 10 IF IN1 = 1 THEN START OUT1

Found the clear device button and now my code is working again (well not fully the way I want yet). I guess it can only take so many writes to it before it hangs up or something? I’ll just make sure to clear it before sending new code to test But that sure makes it a pita

I finally got it! still don’t know why it was hanging as I loaded this code before but now that I cleared the unit and reloaded this it seems to be working. Now I just have to scale it up to 9 inputs and outputs.
10 IF+ IN1 THEN START VAR1 VAR3 = TIME VAR2 = 0
20 REM
30 REM
40 IF+ IN2 AND VAR2 = 0 AND VAR1 AND NOT IN3 THEN START OUT2 VAR2 = TIME GOTO 60
50 IF+ IN3 AND VAR2 = 0 AND VAR1 AND NOT IN2 THEN START OUT3 VAR2 = TIME GOTO 60
60 IF VAR2 > 0 AND VAR2 + 5 < TIME THEN VAR1 = 0 STOP OUT2 STOP OUT3 VAR2 = 0
70 IF VAR1 = 1 AND VAR3 + 00:01:00 < TIME THEN STOP VAR1
80 END

Some suggestions:
Please break the compound lines into separate program lines. The system may be handling them in your testing but I wouldnt rely on it. One thing happening per line makes things easier for the next person debugging this in 5 years.

10 IF+ IN1 THEN START VAR1 VAR3 = TIME VAR2 = 0
Becomes:
10 IF+ IN1 THEN START VAR1
11 IF+ IN1 THEN VAR3 = TIME
11 IF+ IN1 THEN VAR2 = 0

And I’ll say it again, avoid gotos if possible. The one in line 40 is a short jump so that’s not so bad but the one in line 50 just jumps to line 60 which is going to happen anyway. That kind’a highlights my tip to avoid gotos, they make debuging more complex than it needs to be.

Last tip: Give all the items names like SWITCH1 and TIMER1, LIGHTS1 etc. This will make it easier to see what is going on.

2 Likes

Here’s the sequence you mentioned:
I am try to make a selection process that when one input is toggled (IN1) that the user has 3 minutes to select one of 9 inputs (IN2-10) which then turns on a corresponding output (OUT2-10).

And it appears each output should stay on for 5 seconds so here’s my first crack at it. Make sure that TIMER1 is in the units of TIME, not hours, minutes, or seconds. ACTMODE is a flag, on off range.

10 IF+ SWITCH1 THEN TIMER1 = 0:03:00
20 IF TIMER1 > 0:0:0 THEN TIMER1 = TIMER1 - 0:0:01
30 IF TIMER1 > 0:0:0 THEN START ACTMODE ELSE STOP ACTMODE
40 IF+ SWITCH2 AND ACTMODE THEN START OUT2
50 IF+ SWITCH3 AND ACTMODE THEN START OUT3
60 IF+ SWITCH4 AND ACTMODE THEN START OUT4
70 IF+ SWITCH5 AND ACTMODE THEN START OUT5
80 IF+ SWITCH6 AND ACTMODE THEN START OUT6
90 IF TIME-ON( OUT1 ) > 0:0:05 THEN STOP OUT1
90 IF TIME-ON( OUT2 ) > 0:0:05 THEN STOP OUT2
90 IF TIME-ON( OUT3 ) > 0:0:05 THEN STOP OUT3
90 IF TIME-ON( OUT4 ) > 0:0:05 THEN STOP OUT4
90 IF TIME-ON( OUT5 ) > 0:0:05 THEN STOP OUT5
90 IF TIME-ON( OUT6 ) > 0:0:05 THEN STOP OUT6

You’ll probably want to add some logic to prevent the user from hitting additional switches when one output is active. It’ll be best to add a variable and use that as a flag in a new section of code. Avoid long complex program lines that do everything in a single line. Lines further down will overide the lines further up so you can use that feature to keep each program line short.

2 Likes

Thank you and sorry. I’m still way new at this. But I’m determined. I’ll revise now I’m starting to somewhat get it.

1 Like

So i just loaded your code and no outputs work? I load mine back in and they work when tested? Not sure why? I’m just toggling the inputs on and off In software if that makes any difference? I’ll definitely need to revise my code though as I will have to add a lot of NOT statements for the other 7 inputs if I stay like I have it. Also I see other spots that are redundant (2 places where VAR =0

I didnt actually run and debug my program but its a good start on what to do.

One thing that may be catching you up is you will need to name your variables, inputs and outputs to the same as mine, SWITCH1, ACTMODE and so on, otherwise they will be treated as local variables. You can see which is what by the color in the editor, local variables will be greyish in color and items with user defined names will be a solid blue I think it is.

Hello;

I’m kind of lost with the sequence of operation that is described.

I understood:

  1. When INPUT1 is ON, START a 3 minutes countdown

  2. Before the countdown ends, Select ONLY one (1) of nine (9) additional switches

  3. If the countdown reach 0:00 before any switch is selected, then:
    a. turn INPUT1 OFF, and
    b. disable all nine (9) switches and
    c. turn OFF all switched outputs

  4. If a switch is selected before the countdown reach 0:00 then:
    a. start the corresponding output, AND
    b. disable the rest of the outputs, AND
    c. turn OFF INPUT1, AND
    d. STOP the 3 minutes countdown

  5. The Output selected will stay ON for five (5) seconds

  6. When the five (5) seconds are spent, turn OFF the Output

Sounds like a good challenge, anyone up for scratching something out? Its all IF THIS, THEN THAT, type logic plus some timers. The trick is to create a VAR to hold a mode or state, use your logic statements to operate on that mode. Create some separate variables for timers of the states, that way you can put the timers on the graphics display and debug easier.

1 Like