Skip to main content

Meadow.Foundation.Sensors.Hid.Xpt2046

Xpt2046
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Hid.Xpt2046

Code Example

private Xpt2046 touchScreen;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

var i2cBus = Device.CreateI2cBus(I2cBusSpeed.Fast);

touchScreen = new Xpt2046(
Device.CreateSpiBus(),
Device.Pins.D04.CreateDigitalInterruptPort(InterruptMode.EdgeFalling, ResistorMode.InternalPullUp),
Device.Pins.D05.CreateDigitalOutputPort(true));

touchScreen.TouchDown += TouchScreen_TouchDown;

return Task.CompletedTask;
}

private void TouchScreen_TouchDown(ITouchScreen sender, TouchPoint point)
{
Resolver.Log.Info($"Touch at location: X:{point.ScreenX}, Y:{point.ScreenY}");
}

Sample project(s) available on GitHub