Tilt Sensor

BrickLink item

class buildhat.TiltSensor(port)

Tilt sensor

Parameters:

port – Port of device

Raises:

DeviceError – Occurs if there is no tilt sensor attached to port

callback(func)

Set callback function

Parameters:

func – Callback function

property connected

Whether device is connected or not

Returns:

Connection status

static desc_for_id(typeid)

Translate integer type id to something more descriptive than the device name

Parameters:

typeid – Type of device

Returns:

Description of device

property description

Device on port info

Returns:

Device description

deselect()

Unselect data from mode

get()

Extract information from device

Returns:

Data from device

Raises:

DeviceError – Occurs if device not in valid mode

get_tilt()

Return the tilt from tilt sensor

Returns:

Tilt from tilt sensor

Return type:

tuple

property interval

Interval between data points in milliseconds

Getter:

Gets interval

Setter:

Sets interval

Returns:

Device interval

Return type:

int

isconnected()

Whether it is connected or not

Raises:

DeviceError – Occurs if device no longer the same

mode(modev)

Set combimode or simple mode

Parameters:

modev – List of tuples for a combimode, or integer for simple mode

property name

Determine name of device on port

Returns:

Device name

static name_for_id(typeid)

Translate integer type id to device name (python class)

Parameters:

typeid – Type of device

Returns:

Name of device

off()

Turn off sensor

on()

Turn on sensor

reverse()

Reverse polarity

select()

Request data from mode

Raises:

DeviceError – Occurs if device not in valid mode

property typeid

Type ID of device

Returns:

Type ID

property typeidcur

Type ID currently present

Returns:

Type ID

Example

"""Example using tilt sensor"""

from time import sleep

from buildhat import TiltSensor

tilt = TiltSensor('A')

for _ in range(50):
    print(tilt.get_tilt())
    sleep(0.1)