void setPortDutyCycle(int ind, int percent)

Sets the duty cycle of the specified port/pin

Security

Trust Level Required: Full Trust

Parameters

Name Description
ind int
The port/pin index. The pin must support Pulse Width Modulation (PWM).
percent int
The new duty cycle as a percentage (0 - 100) of the time the signal is on/high

Return

Nothing returned

Remarks

Pulse Width Modulation (PWM) ports/pins can set a variable duty cycle that simulates an analog signal for certain applications. For example, controlling LED brightness.

Examples


// Steps the duty cycle up to 100% and back down again in 25% increments
var pin = 33;
var dutyCycle = 0;
var up = true;
setInterval(function() {
	up = dutyCycle == 100 ? false : dutyCycle == 0 ? true : up;
	dutyCycle = up ? dutyCycle + 25 : dutyCycle - 25;
	KioGPIOBoard.setPortDutyCycle(pin - 1, dutyCycle); // Subtract 1 from the pin number for 0 indexing
}, 1000);

Requirements

KioWare OS (Linux®) version 1.0 or greater.


Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.