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 Python 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 |
int | The digital port, such as d0. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
Gives back: int. 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 |
int | The digital port, such as d0. |
dutyCycle |
int | The duty cycle, 0 to 100 percent; higher values are treated as 100. |
ezbIndex |
int | 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 |
int | The digital port, such as d0. |
lowCycle |
int | The lowest duty cycle that can be chosen, 0 to 100 percent. |
highCycle |
int | The highest duty cycle that can be chosen, 0 to 100 percent. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
Gives back: int. The random duty cycle that was chosen.