- All Implemented Interfaces:
Describable,Identity,Lifecycle,Extension,IO<Pwm,,PwmConfig, PwmProvider> OnOff<Pwm>,OnOffRead<Pwm>,OnOffWrite<Pwm>,Pwm
Abstract PwmBase class.
- Version:
- $Id: $Id
- Author:
- Robert Savage (http://www.savagehomeautomation.com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatprotected intprotected booleanFields inherited from class com.pi4j.common.IdentityBase
description, id, logger, metadata, name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd a new PwmPreset to this PWM instance.applyPreset(String name) Apply/recall a PwmPreset by name to this PWM instance.deletePreset(String name) Delete/remove a PwmPreset by name from this PWM instance.intGet the actual frequency value in Hertz (number of cycles per second) applied by the PWM signal generator after the PWM signal is turned 'ON'.floatGet the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period.intGet the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should attempt to output when the PWM signal is turned 'ON'.Get a single PwmPreset from this PWM instance by the preset's name.Get all the PwmPreset instances assigned to this PWM instance.initialize(Context context) initialize.booleanisOn()Get the PWM signal ON/ENABLED state.voidsetDutyCycle(Number dutyCycle) Set the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period.voidsetFrequency(int frequency) Set the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should use when the PWM signal is turned 'ON'.shutdown.Methods inherited from class com.pi4j.common.IdentityBase
description, id, metadata, nameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.pi4j.common.Identity
description, getDescription, getId, getMetadata, getName, id, metadata, name
-
Field Details
-
frequency
protected int frequency -
dutyCycle
protected float dutyCycle -
onState
protected boolean onState -
presets
-
-
Constructor Details
-
PwmBase
Constructor for PwmBase.
- Parameters:
provider- aPwmProviderobject.config- aPwmConfigobject.
-
-
Method Details
-
getDutyCycle
Get the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period. The duty-cycle range is valid from 0 to 100 including factional values. (Values above 50% mean the signal will remain HIGH more time than LOW.) Example: A value of 50 represents a duty-cycle where half of the time period the signal is LOW and the other half is HIGH.- Specified by:
getDutyCyclein interfacePwm- Returns:
- duty-cycle value expressed as a percentage (rage: 0-100)
- Throws:
IOException- if fails to communicate with the PWM pin
-
getFrequency
Get the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should attempt to output when the PWM signal is turned 'ON'. Please note that certain PWM signal generators may be limited to specific frequency bands and may not generate all possible explicit frequency values. After enabling the PWM signal using the 'on(..) method, you can check the 'Pwm::frequency()' or 'Pwm::getFrequency()' properties to determine what frequency the PWM generator actually applied.- Specified by:
getFrequencyin interfacePwm- Returns:
- the configured frequency (Hz) that is used when turning the PWM signal to the 'ON' state.
- Throws:
IOException- if fails to communicate with the PWM pin
-
getActualFrequency
Get the actual frequency value in Hertz (number of cycles per second) applied by the PWM signal generator after the PWM signal is turned 'ON'. Please note that certain PWM signal generators may be limited to specific frequency bands and may not generate all possible explicit frequency values. After enabling the PWM signal using the 'on(...)' method, you can call this method to determine what frequency the PWM generator actually applied.- Specified by:
getActualFrequencyin interfacePwm- Returns:
- the actual frequency (Hz) applied by the PWM generator when the PWM signal is set to the 'ON' state.
- Throws:
IOException- if fails to communicate with the PWM pin
-
setDutyCycle
Set the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period. The duty-cycle range is valid from 0 to 100 including factional values. This method will not update a live PWM signal, but rather stage the duty-cycle value for subsequent call to the 'Pwm::On()' method. Call 'Pwm::On()' if you wish to make a live/ immediate change to the duty-cycle on an existing PWM signal. (Values above 50% mean the signal will remain HIGH more time than LOW.) Example: A value of 50 represents a duty-cycle where half of the time period the signal is LOW and the other half is HIGH.- Specified by:
setDutyCyclein interfacePwm- Parameters:
dutyCycle- duty-cycle value expressed as a percentage (rage: 0-100)- Throws:
IOException- if fails to communicate with the PWM pin
-
setFrequency
Set the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should use when the PWM signal is turned 'ON'. Note: This method will not update a live PWM signal, but rather stage the frequency value for subsequent call to the 'Pwm::On()' method. Call 'Pwm::On()' if you wish to make a live/immediate change to the duty-cycle on an existing PWM signal.- Specified by:
setFrequencyin interfacePwm- Parameters:
frequency- the number of cycles per second (Hertz)- Throws:
IOException- if fails to communicate with the PWM pin
-
isOn
public boolean isOn()Get the PWM signal ON/ENABLED state. -
initialize
initialize.
- Specified by:
initializein interfaceLifecycle- Overrides:
initializein classIOBase<Pwm,PwmConfig, PwmProvider> - Parameters:
context- aContextobject.- Returns:
- a T object.
- Throws:
InitializeException- if an error occurs during initialization.
-
shutdown
shutdown.
- Specified by:
shutdownin interfaceLifecycle- Overrides:
shutdownin classIOBase<Pwm,PwmConfig, PwmProvider> - Parameters:
context- aContextobject.- Returns:
- a T object.
- Throws:
ShutdownException- if an error occurs during shutdown.
-
getPresets
Get all the PwmPreset instances assigned to this PWM instance.- Specified by:
getPresetsin interfacePwm- Returns:
- a map of PwmPresets indexed/cataloged by preset name.
-
getPreset
Get a single PwmPreset from this PWM instance by the preset's name. -
deletePreset
Delete/remove a PwmPreset by name from this PWM instance.- Specified by:
deletePresetin interfacePwm- Parameters:
name- preset name string- Returns:
- the deleted PWM Preset instance
-
addPreset
Add a new PwmPreset to this PWM instance. You can create new PWM preset instance using the 'PwmPreset::newBuilder(name)' static factory method. -
applyPreset
Apply/recall a PwmPreset by name to this PWM instance. This will update the PWM signal with the configured PWM frequency and duty-cycle defined in the preset object.- Specified by:
applyPresetin interfacePwm- Parameters:
name- preset name string- Returns:
- the deleted PWM Preset instance
- Throws:
IOException- if fails to communicate with the PWM pin
-