---
title: "Touchscreen"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/drivers/touch/
last_updated: 2026-11-17
sdk_version: 4.44
---
# Touchscreen

Source: https://developer.repebble.com/pebbleos/docs/samples/drivers/touch/

This sample powers the touchscreen, `TOUCH`, up for 10 seconds and prints where each touch starts and ends, by polling `pbl_touch_get_last()`. It also prints the properties of the panel. `pbl_touch_enable()` and `pbl_touch_disable()` count users: the controller stays powered until the last user disables it.

The driver also reports touches to the input subsystem as events, which [Input events](https://developer.repebble.com/pebbleos/docs/samples/subsys/input/events.md) shows. That is what the system uses, because polling can miss a touch shorter than the polling period.

On a watch, touch the screen while the sample runs. On the emulator, use `pbl emulator touch` or `pbl emulator swipe`; on a native board, click in the display window.

Run:

`pbl samples samples/drivers/touch`

Boards:

every board

## Sources

src/main.c

```
#include \<stdint.h\>#include \<stdio.h\>#include \<pbl/drivers/touch.h\>#include \<pbl/kernel/delay.h\>#include \<pbl/kernel/time.h\>#define LISTEN\_S 10#define POLL\_MS 20static const char \*prv\_yes\_no(bool value) {return value ? "yes" : "no";}int main(void) {const struct pbl\_touch\_props \*props = pbl\_touch\_get\_props(TOUCH);struct pbl\_touch\_sample prev = {};uint64\_t end;int touches = 0;int ret;/\* The coordinates come mapped to the display: the properties say how the panel is mounted. \*/printf("touch: %dx%d, inverted x: %s, inverted y: %s, swapped: %s\n", props-\>size\_x,props-\>size\_y, prv\_yes\_no(props-\>inverted\_x), prv\_yes\_no(props-\>inverted\_y),prv\_yes\_no(props-\>swapped\_x\_y));/\* Enabling counts users: the controller stays powered until the last one disables it. \*/ret = pbl\_touch\_enable(TOUCH);if (ret != 0) {fprintf(stderr, "touch: enable failed (%d)\n", ret);return ret;}printf("touch: listening for %d s\n", LISTEN\_S);/\* \* Touches also go to the input subsystem, as events: polling the last sample is enough to \* follow a finger here. \*/end = pbl\_uptime\_ms() + LISTEN\_S \* 1000U;while (pbl\_uptime\_ms() \< end) {struct pbl\_touch\_sample now;pbl\_touch\_get\_last(TOUCH, &now);if (now.down && !prev.down) {printf("touch: down at %d,%d\n", now.x, now.y);touches++;} else if (!now.down && prev.down) {printf("touch: up at %d,%d\n", prev.x, prev.y);}prev = now;pbl\_sleep\_ms(POLL\_MS);}printf("touch: %d touches\n", touches);ret = pbl\_touch\_disable(TOUCH);if (ret != 0) {fprintf(stderr, "touch: disable failed (%d)\n", ret);return ret;}printf("touch: enabled after disable: %s\n", prv\_yes\_no(pbl\_touch\_is\_enabled(TOUCH)));printf("Sample done\n");return 0;}
```

## Output

```
touch: \d+x\d+, inverted x: (yes|no), inverted y: (yes|no), swapped: (yes|no)
touch: listening for 10 s
touch: \d+ touches
touch: enabled after disable: no
Sample done
```

Generated from PebbleOS [9e782207f](https://github.com/coredevices/pebbleos/commit/9e782207f53f8f1c02f7b13ea40cdc092d7bab3d). This page is maintained in the pebbleos repository: [docs/samples/drivers/touch.md](https://github.com/coredevices/pebbleos/blob/9e782207f53f8f1c02f7b13ea40cdc092d7bab3d/docs/samples/drivers/touch.md).
