How to set Digital Outputs on or off

Hello,

Help a beginner, is there a way to set digital outputs say [2 to 7] on or off all at once instead of switching each individually. I am using a Led light tower; it is working but instead of multiple lines of code was wondering can i do this with less lines of code.

cheers
Steve

There are others here who I’m sure can give a more definitive answer, but I doubt it.

Typically for something like that I like to use a script - it’s easy to copy & paste repetitive things like that.

Here’s a short pair of scripts which turn a couple outputs on & off:

edit - the bold lines are comments - this app interprets the pound sign as bolding

def actuator_UP():

DPDT relay OFF, SPST relay ON

set_standard_digital_out(2, False)
set_standard_digital_out(3, False)
set_standard_digital_out(2, True)
sleep(1.2)
set_standard_digital_out(2, False) 

end

def actuator_DOWN():

Both relays ON

set_standard_digital_out(2, False)
set_standard_digital_out(3, True)
set_standard_digital_out(2, True) 	
sleep(1.2)  			
set_standard_digital_out(2, False)
set_standard_digital_out(3, False)

end

I suppose you could replace the output number with an array variable and loop when the number of outputs gets larger.

similar to what @dpeva said the easiest thing is to create a script function and then simply call that with the state that you want. A simple implementation could be

def set_standard_digital_outputs(startPort, state) # state would be an array of booleans equal to the number of outputs you want to control
  local port = startPort
  local endPort = startPort + length(state)
  while port<endPort:
    set_standard_digital_out(port, state[port])
    port = port +1
  end
end

In your program, you would add a script line and then you could pass it the state as an array of booleans telling it to turn on or off as well as the port to start at for instance

set_standard_digital_outputs(2, [True, True, True, False, True. False])

That would set outputs 2-7 to the following conditions
output 2 - On
output 3 - On
output 4 - On
output 5 - Off
output 6 - On
output 7 - On

Remember that the port would be an integer between 0 and 7 as those are the standard digital output port numbers

ok, thank you very much.

Steve