Meadow.Foundation.ICs.IOExpanders.Pca9685
Pca9685 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Pca9685 pca9685;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
var i2CBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);
pca9685 = new Pca9685(i2CBus, new Meadow.Units.Frequency(50, Meadow.Units.Frequency.UnitType.Hertz), (byte)Pca9685.Addresses.Default);
pca9685.Initialize();
return base.Initialize();
}
public override Task Run()
{
var port0 = pca9685.CreatePwmPort(0, 0.05f);
var port7 = pca9685.CreatePwmPort(7);
port0.Start();
port7.Start();
return base.Run();
}
Sample project(s) available on GitHub
Wiring Example
To wire a PCA9685 to your Meadow board, connect the following:
Class Pca9685
Represents PCA9685 IC
Assembly: Pca9685.dll
View Source
Declaration
public class Pca9685 : II2cPeripheral
Implements:
Meadow.Hardware.II2cPeripheral
Properties
DefaultI2cAddress
The default I2C address for the peripheral
View Source
Declaration
public byte DefaultI2cAddress { get; }
i2cBus
The I2C bus connected to the pca9685
View Source
Declaration
protected II2cBus i2cBus { get; set; }
Fields
i2cComms
I2C Communication bus used to communicate with the peripheral
View Source
Declaration
protected readonly II2cCommunications i2cComms
Methods
Initialize()
Initializes the PCA9685 IC
View Source
Declaration
public virtual void Initialize()
CreatePwmPort(byte, float)
Create a IPwmPort on the specified pin
View Source
Declaration
public virtual IPwmPort CreatePwmPort(byte portNumber, float dutyCycle = 0.5)
Returns
Meadow.Hardware.IPwmPort
: IPwmPort
Parameters
Type | Name | Description |
---|---|---|
System.Byte | portNumber | The port number (0-15) |
System.Single | dutyCycle | The duty cycle for that port |
SetPin(byte, bool)
Turns the specified pin On or Off
View Source
Declaration
public virtual void SetPin(byte pin, bool on)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | pin | The pin to set |
System.Boolean | on | true is on, false if off |
SetPwm(byte, int, int)
Set the values for specified output pin.
View Source
Declaration
public virtual void SetPwm(byte pin, int on, int off)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | pin | The pwm Pin |
System.Int32 | on | LED{X}_ON_L and LED{X}_ON_H register value |
System.Int32 | off | LED{X}_OFF_L and LED{X}_OFF_H register value |
Implements
Meadow.Hardware.II2cPeripheral