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

Class Xpt2046

Represents an XPT2046 4-wire touch screen controller

Assembly: Xpt2046.dll
View Source
Declaration
public class Xpt2046 : ICalibratableTouchscreen, ITouchScreen

Implements:
Meadow.Hardware.ICalibratableTouchscreen, Meadow.Hardware.ITouchScreen

Properties

Rotation

Gets the current rotation of the touchscreen

View Source
Declaration
public RotationType Rotation { get; }

IsCalibrated

Returns <b>true</b> if the touchscreen has been calibrated, otherwise <b>false</b>

View Source
Declaration
public bool IsCalibrated { get; }

IsTouched

Returns <b>true</b> if the touchscreen is currently being touched, otherwise <b>false</b>

View Source
Declaration
public bool IsTouched { get; }

Methods

SetCalibrationData(IEnumerable<CalibrationPoint>)

Sets the calibration data for the touchscreen

View Source
Declaration
public void SetCalibrationData(IEnumerable<CalibrationPoint> data)
Parameters
TypeNameDescription
System.Collections.Generic.IEnumerable<Meadow.Hardware.CalibrationPoint>dataThe calibration point

Events

TouchDown

Event raised when the touchscreen is pressed

View Source
Declaration
public event TouchEventHandler? TouchDown
Event Type

Meadow.Hardware.TouchEventHandler

TouchUp

Event raised when the touchscreen is released

View Source
Declaration
public event TouchEventHandler? TouchUp
Event Type

Meadow.Hardware.TouchEventHandler

TouchClick

Event raised when a cycle of press and release has occurred

View Source
Declaration
public event TouchEventHandler? TouchClick
Event Type

Meadow.Hardware.TouchEventHandler

TouchMoved

Event raised when a cycle of press and release has occurred

View Source
Declaration
public event TouchEventHandler? TouchMoved
Event Type

Meadow.Hardware.TouchEventHandler

Implements

  • Meadow.Hardware.ICalibratableTouchscreen
  • Meadow.Hardware.ITouchScreen