Well isn't the important part NOT to have any delays?
And if you want a blinky Light as well (which now introduces a maximum 10mS delay in this example)...Code:loop: if portb.0 = 1 then ' Switch is OFF gosub sub2 else ' otherwise it's ON gosub sub1 endif Goto Loop sub1: low 11 ' Turn Off SAW immediately low 10 ' Turn Off power feed low 9 ' Turn Off Light low 8 ' Turn Off Vacuum Return sub2: high 8 ' Turn On Vacuum high 9 ' Turn On Light high 10 ' Turn On Power Feed high 11 ' Turn On SAW Return end
Why not also ALIAS your Ports, so they're easier to program... at the start you declare your aliases...Code:counter=0 loop: if portb.0 = 1 then ' Switch is OFF gosub sub2 else ' otherwise it's ON gosub sub1 endif counter=counter+1 If Counter=>100 then ' approx 1 second toggle toggle portb.5 Counter=0 endif Pause 10 Goto Loop sub1: low 11 ' Turn Off SAW immediately low 10 ' Turn Off power feed low 9 ' Turn Off Light low 8 ' Turn Off Vacuum Return sub2: high 8 ' Turn On Vacuum high 9 ' Turn On Light high 10 ' Turn On Power Feed high 11 ' Turn On SAW Return end
LED var PortB.5
then in your program you can write Toggle LED instead of Toggle PortB.5
The bonus is, if you then decide to move the LED to a different port/pin, you make your change on ONE line of your program, and hey-presto, it doesn't matter how many times you've used LED, they all get reassigned.
Likewise alias, VACUUM, POWERFEED, LIGHT and SAW and you can then go...
Low SAW
Low POWERFEED
Low LIGHT
Low VACUUM
which makes fare more easier program understanding...




Bookmarks