Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

Pwm

public interface Pwm
implements Closeable

com.google.android.things.pio.Pwm
Known Indirect Subclasses


Controls a PWM pin.

Opening a PWM pin takes ownership of it for the whole system, preventing anyone else from opening/accessing the PWM until you call close(). Forgetting to call close() will prevent anyone (including the same process/app) from using the PWM.

Summary

Public methods

abstract void close()

Releases the PWM pin.

default String getName()

Returns the I/O name.

abstract void setEnabled(boolean enabled)

Enables the PWM pin.

abstract void setPwmDutyCycle(double duty_cycle)

Sets the duty cycle.

abstract void setPwmFrequencyHz(double freq_hz)

Sets the frequency of the signal.

Inherited methods

From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public methods

close

void close ()

Releases the PWM pin.

This must be called in order for the PWM pin to be released and be available to other users. Closing a PWM does not change its state, for example if it is closed while enabled, it will continue to output the same PWM signal until another user opens it and changes its state.

Throws
IOException if the PWM is already closed.

getName

String getName ()

Returns the I/O name.

Returns
String

setEnabled

void setEnabled (boolean enabled)

Enables the PWM pin.

Frequency must be set via setPwmFrequencyHz(double) before enabling the pin, but frequency and duty cycle settings can be set in both enabled and disabled state and will be remembered if the PWM is disabled and then re-enabled.

Parameters
enabled boolean: True to enable the PWM, false to disable.

Throws
IOException

setPwmDutyCycle

void setPwmDutyCycle (double duty_cycle)

Sets the duty cycle.

Parameters
duty_cycle double: A double between 0 and 100 (inclusive).

Throws
IOException
IllegalArgumentException
IOException

setPwmFrequencyHz

void setPwmFrequencyHz (double freq_hz)

Sets the frequency of the signal.

Parameters
freq_hz double: Frequency in Hertz to use for the signal. Must be positive.

Throws
IOException
IllegalArgumentException
IOException