Meadow.Foundation.Sensors.Hid.Tsc2004
Tsc2004 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Tsc2004 touchScreen;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
var i2cBus = Device.CreateI2cBus(I2cBusSpeed.Fast);
touchScreen = new Tsc2004(i2cBus)
{
DisplayWidth = 240,
DisplayHeight = 320,
XMin = 260,
XMax = 3803,
YMin = 195,
YMax = 3852,
Rotation = RotationType._90Degrees
};
return Task.CompletedTask;
}
public override Task Run()
{
return Task.Run(() =>
{
Point3d pt;
while (true)
{
if (touchScreen.IsTouched())
{
pt = touchScreen.GetPoint();
Resolver.Log.Info($"Location: X:{pt.X}, Y:{pt.Y}, Z:{pt.Z}");
}
Thread.Sleep(0);
}
});
}
Sample project(s) available on GitHub
Wiring Example
To wire a Tsc2004 to your Meadow board, connect the following:
Tsc2004 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
Class Tsc2004
Represents a TSC2004 4-wire touch screen controller
Assembly: Tsc2004.dll
View Source
public class Tsc2004 : II2cPeripheral
Implements:
Meadow.Hardware.II2cPeripheral
Properties
DefaultI2cAddress
The default I2C address for the peripheral
View Source
public byte DefaultI2cAddress { get; }
XMin
Minimum X value of touchscreen (defaults to 366)
View Source
public int XMin { get; set; }
XMax
Maximum X value of touchscreen (defaults to 3567)
View Source
public int XMax { get; set; }
YMin
Minimum Y value of touchscreen (defaults to 334)
View Source
public int YMin { get; set; }
YMax
Maximum Y value of touchscreen (defaults to 3787)
View Source
public int YMax { get; set; }
DisplayWidth
Width of display in pixels at default rotation
View Source
public int DisplayWidth { get; set; }
DisplayHeight
Height of display in pixels at default rotation
View Source
public int DisplayHeight { get; set; }
Rotation
Touchscreen rotation
View Source
public RotationType Rotation { get; set; }
Fields
i2cComms
I2C Communication bus used to communicate with the peripheral
View Source
protected readonly II2cCommunications i2cComms
Methods
GetPoint()
Get the current scaled touch location
View Source
public Point3d GetPoint()
Returns
Meadow.Foundation.Graphics.Point3d
GetPointRaw()
Get the current raw touch location
View Source
public Point3d GetPointRaw()
Returns
Meadow.Foundation.Graphics.Point3d
IsTouched()
Does the screen detect an active touch
View Source
public bool IsTouched()
Returns
System.Boolean
: True if touched### IsBufferEmpty()
Is the touch buffer empty
View Source
public bool IsBufferEmpty()
Returns
System.Boolean
: True if empty
Implements
Meadow.Hardware.II2cPeripheral