Connection Diagnostic icon Connection Diagnostic — Diagnose EZ-B Wi-Fi connection issues with verbose EZ-B communication logging, ping tests, log export and diagnostic reports for Synthiam support. Try it →
 

PWM

Set the pulse width modulation (PWM) of a digital port, from 0 to 100 percent. PWM switches a port on and off very quickly, so the share of time it is on sets an LED's brightness or a motor driver's speed.

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


Commands

Command What it does
PWM.get Gets the last PWM duty cycle set on a digital port.
PWM.set Sets the PWM duty cycle of a digital port as a percentage, where 0 stops the PWM and 100 is fully on.
PWM.setRandom Sets the PWM of a digital port to a random duty cycle from lowCycle to highCycle, both included, trying not to repeat the last random number.

Details

PWM.get

Gets the last PWM duty cycle set on a digital port. This is remembered by ARCx, not read from the EZB.

PWM.get(port)
PWM.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: number. The duty cycle, 0 to 100 percent, which is 0 when the PWM is stopped or was never set.

PWM.set

Sets the PWM duty cycle of a digital port as a percentage, where 0 stops the PWM and 100 is fully on. Does nothing when the EZB is not connected, and raises an error if its firmware has no PWM.

PWM.set(port, dutyCycle)
PWM.set(port, dutyCycle, ezbIndex)
Value Type What it is
port number The digital port, such as d0.
dutyCycle number The duty cycle, 0 to 100 percent; higher values are treated as 100.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

PWM.setRandom

Sets the PWM of a digital port to a random duty cycle from lowCycle to highCycle, both included, trying not to repeat the last random number. Does nothing when the EZB is not connected.

PWM.setRandom(port, lowCycle, highCycle)
PWM.setRandom(port, lowCycle, highCycle, ezbIndex)
Value Type What it is
port number The digital port, such as d0.
lowCycle number The lowest duty cycle that can be chosen, 0 to 100 percent.
highCycle number The highest duty cycle that can be chosen, 0 to 100 percent.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number. The random duty cycle that was chosen.