RoboidControl-python/Things/TouchSensor.py

21 lines
750 B
Python

from Thing import Thing
class TouchSensor(Thing):
"""! A sensor which can detect touches
"""
def __init__(self, owner = None, parent = None):
"""! Create a touch sensor
"""
super().__init__(owner = owner, parent = parent, type = Thing.Type.TouchSensor)
## Value which is true when the sensor is touching something, false otherwise
self.touched_something = False
def ProcessBinary(self, bytes):
"""! Function to extract the touch state received in a binary message
"""
self.touched_something = bytes[0] == 1
if self.touched_something:
print(f"{self.name} touched something!")
else:
print(f"{self.name} touching nothing")