Meadow.Foundation.Sensors.Hid.Mpr121
Mpr121 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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:
Class Mpr121
Represents the MPR121 12-Key Capacitive Touch Sensor
Assembly: Mpr121.dll
View Source
public class Mpr121 : II2cPeripheral
Implements:
Meadow.Hardware.II2cPeripheral
Properties
DefaultI2cAddress
The default I2C address for the peripheral
View Source
public byte DefaultI2cAddress { get; }
RefreshPeriod
Gets or sets the period in milliseconds to refresh the channels statuses.
View Source
public int RefreshPeriod { get; set; }
Fields
i2cComms
I2C Communication bus used to communicate with the peripheral
View Source
protected readonly II2cCommunications i2cComms
Methods
ReadChannelStatus(Channels)
Reads the channel status of MPR121 controller.
View Source
public bool ReadChannelStatus(Mpr121.Channels channel)
Returns
System.Boolean
Parameters
Type | Name | Description |
---|---|---|
Meadow.Foundation.Sensors.Hid.Mpr121.Channels | channel | The channel to read status. |
ReadChannelStatuses()
Reads the channel statuses of MPR121 controller.
View Source
public IReadOnlyDictionary<Mpr121.Channels, bool> ReadChannelStatuses()
Returns
System.Collections.Generic.IReadOnlyDictionary<Meadow.Foundation.Sensors.Hid.Mpr121.Channels,System.Boolean>
Events
ChannelStatusesChanged
Notifies about a the channel statuses have been changed. Refresh period can be changed by setting PeriodRefresh property.
View Source
public event EventHandler<ChannelStatusChangedEventArgs> ChannelStatusesChanged
Event Type
System.EventHandler<Meadow.Foundation.Sensors.Hid.ChannelStatusChangedEventArgs>
Implements
Meadow.Hardware.II2cPeripheral