Horizontal Servo icon Horizontal Servo — Mouse-drag horizontal servo control with configurable min/max limits, center/release functions, multi-servo mirroring and direction invert. Try it →
 

Digital

Read and set the digital ports of an EZB. A digital port is either on (true, a voltage) or off (false). Set one to turn an LED or a relay on and off; read one to check a button or a switch. The wait command pauses the script until a port changes.

Where to find it: type Digital. in a JavaScript script, or open the ARCx API view of the script editor and expand Digital


Commands

Command What it does
Digital.get Reads a digital port from the EZB to see whether it is on, meaning voltage is detected.
Digital.set Turns a digital port on or off.
Digital.setRandom Turns a digital port on or off at random, with an even chance of each.
Digital.toggle Reads a digital port from the EZB and switches it to the opposite state, so on becomes off and off becomes on.
Digital.wait Pauses the script until a digital port reads on or off as requested, checking the EZB every 250 ms.

Details

Digital.get

Reads a digital port from the EZB to see whether it is on, meaning voltage is detected. Reads as off when the EZB is not connected.

Digital.get(port)
Digital.get(port, ezbIndex)
Value Type What it is
port number The digital port, such as d0.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: boolean. Whether the port is on.

Digital.set

Turns a digital port on or off. On outputs 3.3 V on an EZ-B v4 (5 V on a v3) and off connects the port to ground.

Digital.set(port, value)
Digital.set(port, value, ezbIndex)
Value Type What it is
port number The digital port, such as d0.
value boolean Whether to turn the port on.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Digital.setRandom

Turns a digital port on or off at random, with an even chance of each.

Digital.setRandom(port)
Digital.setRandom(port, ezbIndex)
Value Type What it is
port number The digital port, such as d0.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: boolean. Whether the port was turned on.

Digital.toggle

Reads a digital port from the EZB and switches it to the opposite state, so on becomes off and off becomes on.

Digital.toggle(port)
Digital.toggle(port, ezbIndex)
Value Type What it is
port number The digital port, such as d0.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: boolean. Whether the port is now on.

Digital.wait

Pauses the script until a digital port reads on or off as requested, checking the EZB every 250 ms. Also returns if the script is stopped while waiting.

Digital.wait(port, valueToWaitFor)
Digital.wait(port, valueToWaitFor, frequencyMs)
Digital.wait(port, valueToWaitFor, frequencyMs, ezbIndex)
Value Type What it is
port number The digital port, such as d0.
valueToWaitFor boolean Whether to wait for the port to be on (otherwise waits for off).
frequencyMs number Optional. How often to check the port, in milliseconds, such as 250.
ezbIndex number Optional. Which EZB to use, 0 being the first one.