touch-cst816s · Recipe
React to touches
Print the touches of a CST816S as they happen, in an event-driven project.
Wire the chip's INT line (and reset, if you have it) to free GPIOs, and use the pin numbers of your board.
<?php
use Baremetal\Events;
use Baremetal\I2c\Bus;
use Baremetal\I2c\Driver\Cst816s;
use Baremetal\Input\{Pressed, Moved, Released, Gesture};
$touch = new Cst816s(new Bus(sda: 11, scl: 10), int: 4, rst: 1, width: 360, height: 360);
Events::listen(Pressed::class, fn(Pressed $e) => printf("down %d,%d\n", $e->x, $e->y));
Events::listen(Moved::class, fn(Moved $e) => printf("move %d,%d\n", $e->x, $e->y));
Events::listen(Released::class, fn(Released $e) => printf("up %d,%d\n", $e->x, $e->y));
Events::listen(Gesture::class, fn(Gesture $e) => printf("gesture %s\n", $e->type->value));
$touch->events();
Require php-baremetal/touch-cst816s and use the event-driven runtime. With a wrong orientation the points
land mirrored or swapped: set mirror_x, mirror_y or swap_xy until a touch in a corner reports that corner.
Related
- Cst816s PHP API
- Touch events Events