Class Pwm
PWM is the Pulse Width Modulation interface to libmraa. It allows the generation of a signal on a pin. Some boards may have higher or lower levels of resolution so make sure you check the board & pin you are using before hand.
Inheritance
Namespace:MraaSharp
Assembly:MraaSharp.dll
Syntax
public class Pwm : IDisposable
Constructors
View SourcePwm(Int32)
Initialise pwm_context, uses board mapping
Declaration
public Pwm(int pin)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pin | The PWM PIN |
Pwm(Int32, Int32)
Initialise pwm_context, raw mode
Declaration
public Pwm(int chipid, int pin)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | chipid | The chip inwhich the PWM is under in SYSFS |
System.Int32 | pin | The PWM PIN |
Properties
View SourceEnable
Set the enable status of the PWM pin. None zero will assume on with output being driven. and 0 will disable the output
Declaration
public bool Enable
{
set;
}
Property Value
Type | Description |
---|---|
System.Boolean |
MaxPeriod
Get the maximum pwm period in us
Declaration
public int MaxPeriod
{
get;
}
Property Value
Type | Description |
---|---|
System.Int32 |
MinPeriod
Get the minimum pwm period in us
Declaration
public int MinPeriod
{
get;
}
Property Value
Type | Description |
---|---|
System.Int32 |
Owner
Change ownership of context
Declaration
public bool Owner
{
set;
}
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
View SourceConfigMilliseconds(Int32, Single)
Set Both Period and DutyCycle on a PWM context
Declaration
public void ConfigMilliseconds(int period, float duty)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | represented in ms. |
System.Single | duty | dutycycle of the pwm signal. |
ConfigPercent(Int32, Single)
Set Both Period and DutyCycle on a PWM context. Duty represented as percentage.
Declaration
public void ConfigPercent(int period, float duty)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | represented in ms. |
System.Single | duty | duty percantage. i.e. 50% = 0.5f |
Dispose()
Declaration
public void Dispose()
SetPeriod(Single)
Set the PWM period as seconds represented in a float
Declaration
public void SetPeriod(float seconds)
Parameters
Type | Name | Description |
---|---|---|
System.Single | seconds | Period represented as a float in seconds |
SetPeriodMicroseconds(Int32)
Set period, microseconds.
Declaration
public void SetPeriodMicroseconds(int us)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | us | Microseconds as period |
SetPeriodMilliseconds(Int32)
Set period, milliseconds.
Declaration
public void SetPeriodMilliseconds(int ms)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ms | Milliseconds for period |
SetPulseWidthMicroseconds(Int32)
Set pulsewidth, microseconds
Declaration
public void SetPulseWidthMicroseconds(int us)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | us | Microseconds for pulsewidth |
SetPulseWidthMicroseconds(Single)
Set pulsewidth, As represnted by seconds in a (float)
Declaration
public void SetPulseWidthMicroseconds(float seconds)
Parameters
Type | Name | Description |
---|---|---|
System.Single | seconds | The duration of a pulse |
SetPulseWidthMilliseconds(Int32)
Set pulsewidth, milliseconds
Declaration
public void SetPulseWidthMilliseconds(int ms)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ms | Milliseconds for pulsewidth |
Write(Single)
Set the ouput duty-cycle percentage, as a float
Declaration
public void Write(float percentage)
Parameters
Type | Name | Description |
---|---|---|
System.Single | percentage | A floating-point value representing percentage of output. The value should lie between 0.0f (representing on 0%) and 1.0f Values above or below this range will be set at either 0.0f or 1.0f |