Remarks
Mpr121 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
<img src="https://img.shields.io/nuget/v/Meadow.Foundation.Sensors.Hid.Mpr121.svg?label=Meadow.Foundation.Sensors.Hid.Mpr121"
style="width: auto; height: -webkit-fill-available;" /></a> |
Code Example
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
var sensor = new Mpr121(Device.CreateI2cBus(Meadow.Hardware.I2cBusSpeed.Standard), 90, 100);
sensor.ChannelStatusesChanged += Sensor_ChannelStatusesChanged;
return Task.CompletedTask;
}
private void Sensor_ChannelStatusesChanged(object sender, ChannelStatusChangedEventArgs e)
{
string pads = string.Empty;
for(int i = 0; i < e.ChannelStatus.Count; i++)
{
if(e.ChannelStatus[(Mpr121.Channels)i] == true)
{
pads += i + ", ";
}
}
var msg = string.IsNullOrEmpty(pads) ? "none" : (pads + "touched");
Resolver.Log.Info(msg);
}
Sample project(s) available on GitHub
Wiring Example
To wire a Mpr121 to your Meadow board, connect the following:
Mpr121 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Characteristic | Locus |
---|---|
Inheritance | System.Object > Mpr121 |
Namespace | Meadow.Foundation.Sensors.Hid |
Assembly | Mpr121.dll |
Syntax
public class Mpr121 : object
Constructors
Mpr121(II2cBus, Byte, Int32, Mpr121.Mpr121Configuration)
Create a new MPR121 keypad object.
Declaration
public Mpr121(II2cBus i2cBus, byte address = null, int refreshPeriod = null, Mpr121.Mpr121Configuration configuration = null)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | |
System.Byte | address | |
System.Int32 | refreshPeriod | |
Mpr121.Mpr121Configuration | configuration |
Properties
RefreshPeriod
Gets or sets the period in milliseconds to refresh the channels statuses.
Declaration
public int RefreshPeriod { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
ReadChannelStatus(Mpr121.Channels)
Reads the channel status of MPR121 controller.
Declaration
public bool ReadChannelStatus(Mpr121.Channels channel)
Parameters
Type | Name | Description |
---|---|---|
Mpr121.Channels | channel | The channel to read status. |
Returns
Type | Description |
---|---|
System.Boolean |
ReadChannelStatuses()
Reads the channel statuses of MPR121 controller.
Declaration
public IReadOnlyDictionary<Mpr121.Channels, bool> ReadChannelStatuses()
Returns
Type | Description |
---|---|
IReadOnlyDictionary<Mpr121.Channels, System.Boolean> |
Events
ChannelStatusesChanged
Notifies about a the channel statuses have been changed. Refresh period can be changed by setting PeriodRefresh property.
Declaration
public event EventHandler<ChannelStatusChangedEventArgs> ChannelStatusesChanged
Event Type
Type | Description |
---|---|
EventHandler<ChannelStatusChangedEventArgs> |