Skip to content

Commit

Permalink
touch.py: adding touch buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
thirdr committed Dec 17, 2024
1 parent 3adb9ec commit 605f9f6
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions modules/py_frozen/touch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
from micropython import const
from machine import I2C, Pin
import math

from machine import I2C, Pin
from micropython import const


class Button:
buttons = []

def __init__(self, x, y, w, h):
self.x = x
self.y = y
self.w = w
self.h = h
self.pressed = False
Button.buttons.append(self)

def is_pressed(self):
return self.pressed

@property
def bounds(self):
return self.x, self.y, self.w, self.h


class FT6236:
TOUCH_INT = const(32)
Expand Down Expand Up @@ -74,3 +94,10 @@ def _handle_touch(self, pin):

if self.debug:
print(self.x, self.y, self.x2, self.y2, self.distance, self.angle, self.state, self.state2)

for button in Button.buttons:
if self.state:
if self.x >= button.x and self.x <= button.x + button.w and self.y >= button.y and self.y <= button.y + button.h:
button.pressed = True
else:
button.pressed = False

0 comments on commit 605f9f6

Please sign in to comment.