Stay organized with collections
Save and categorize content based on your preferences.
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
abstract
void
|
close()
Closes this stream and releases any system resources associated
with it.
|
|
From
interface
java.lang.AutoCloseable
abstract
void
|
close()
Closes this resource, relinquishing any underlying resources.
|
|
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.
getName
String getName ()
Returns the I/O name.
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. |
setPwmDutyCycle
void setPwmDutyCycle (double duty_cycle)
Sets the duty cycle.
Parameters |
duty_cycle |
double : A double between 0 and 100 (inclusive). |
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. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Pwm\n\nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \\| [\\[Expand All\\]](#) \n\nPwm\n===\n\n\n`\npublic\n\n\ninterface\nPwm\n`\n\n\n`\n\n\nimplements\n\n`[Closeable](/reference/java/io/Closeable)`\n\n\n`\n\n|-----------------------------------|\n| com.google.android.things.pio.Pwm |\n\n|---|---|\n| Known Indirect Subclasses [PwmDriver](/reference/com/google/android/things/userdriver/pio/PwmDriver) |----------------------------------------------------------------------------|------------------| | [PwmDriver](/reference/com/google/android/things/userdriver/pio/PwmDriver) | PWM user driver. | ||\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nControls a PWM pin.\n\nOpening a PWM pin takes ownership of it for the whole system, preventing anyone else from\nopening/accessing the PWM until you call [close()](/reference/com/google/android/things/pio/Pwm#close()). Forgetting to call [close()](/reference/com/google/android/things/pio/Pwm#close()) will\nprevent anyone (including the same process/app) from using the PWM.\n\nSummary\n-------\n\n| ### Public methods ||\n|--------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[close](/reference/com/google/android/things/pio/Pwm#close())`() ` Releases the PWM pin. |\n| ` default `[String](/reference/java/lang/String) | ` `[getName](/reference/com/google/android/things/pio/Pwm#getName())`() ` Returns the I/O name. |\n| ` abstract void` | ` `[setEnabled](/reference/com/google/android/things/pio/Pwm#setEnabled(boolean))`(boolean enabled) ` Enables the PWM pin. |\n| ` abstract void` | ` `[setPwmDutyCycle](/reference/com/google/android/things/pio/Pwm#setPwmDutyCycle(double))`(double duty_cycle) ` Sets the duty cycle. |\n| ` abstract void` | ` `[setPwmFrequencyHz](/reference/com/google/android/things/pio/Pwm#setPwmFrequencyHz(double))`(double freq_hz) ` Sets the frequency of the signal. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From interface ` `[java.io.Closeable](/reference/java/io/Closeable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||\n| From interface ` `[java.lang.AutoCloseable](/reference/java/lang/AutoCloseable)` ` |------------------|---------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||\n\nPublic methods\n--------------\n\n### close\n\n```\nvoid close ()\n```\n\nReleases the PWM pin.\n\nThis must be called in order for the PWM pin to be released and be available to other\nusers. Closing a PWM does not change its state, for example if it is closed while enabled,\nit will continue to output the same PWM signal until another user opens it and changes its\nstate.\n\n\u003cbr /\u003e\n\n| Throws ||\n|-----------------------------------------------|-------------------------------|\n| [IOException](/reference/java/io/IOException) | if the PWM is already closed. |\n\n### getName\n\n```\nString getName ()\n```\n\nReturns the I/O name.\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------------------------------------|--------|\n| [String](/reference/java/lang/String) | \u003cbr /\u003e |\n\n### setEnabled\n\n```\nvoid setEnabled (boolean enabled)\n```\n\nEnables the PWM pin.\n\nFrequency must be set via [setPwmFrequencyHz(double)](/reference/com/google/android/things/pio/Pwm#setPwmFrequencyHz(double)) before enabling the pin, but\nfrequency and duty cycle settings can be set in both enabled and disabled state and\nwill be remembered if the PWM is disabled and then re-enabled.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|-------------------------------------------------------------|\n| `enabled` | `boolean`: True to enable the PWM, false to disable. \u003cbr /\u003e |\n\n| Throws ||\n|-----------------------------------------------|---|\n| [IOException](/reference/java/io/IOException) | |\n\n### setPwmDutyCycle\n\n```\nvoid setPwmDutyCycle (double duty_cycle)\n```\n\nSets the duty cycle.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------------|----------------------------------------------------------|\n| `duty_cycle` | `double`: A double between 0 and 100 (inclusive). \u003cbr /\u003e |\n\n| Throws ||\n|---------------------------------------------------------------------------|-------------|\n| | IOException |\n| [IllegalArgumentException](/reference/java/lang/IllegalArgumentException) | |\n| [IOException](/reference/java/io/IOException) | |\n\n### setPwmFrequencyHz\n\n```\nvoid setPwmFrequencyHz (double freq_hz)\n```\n\nSets the frequency of the signal.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|------------------------------------------------------------------------------|\n| `freq_hz` | `double`: Frequency in Hertz to use for the signal. Must be positive. \u003cbr /\u003e |\n\n| Throws ||\n|---------------------------------------------------------------------------|-------------|\n| | IOException |\n| [IllegalArgumentException](/reference/java/lang/IllegalArgumentException) | |\n| [IOException](/reference/java/io/IOException) | |\n\n-\n\n Interfaces\n ----------\n\n - [Gpio](/reference/com/google/android/things/pio/Gpio)\n - [GpioCallback](/reference/com/google/android/things/pio/GpioCallback)\n - [I2cDevice](/reference/com/google/android/things/pio/I2cDevice)\n - [Pwm](/reference/com/google/android/things/pio/Pwm)\n - [SpiDevice](/reference/com/google/android/things/pio/SpiDevice)\n - [UartDevice](/reference/com/google/android/things/pio/UartDevice)\n - [UartDeviceCallback](/reference/com/google/android/things/pio/UartDeviceCallback)\n-\n\n Classes\n -------\n\n - [PeripheralManager](/reference/com/google/android/things/pio/PeripheralManager)"]]