File: sensor_touch.py

package info (click to toggle)
nxt-python 3.5.1-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 816 kB
  • sloc: python: 6,857; xml: 22; makefile: 20; sh: 4
file content (18 lines) | stat: -rw-r--r-- 532 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/python3
"""NXT-Python tutorial: use touch sensor."""
import time

import nxt.locator
import nxt.sensor
import nxt.sensor.generic

with nxt.locator.find() as b:
    # Get the sensor connected to port 1, not a digital sensor, must give the sensor
    # class.
    mysensor = b.get_sensor(nxt.sensor.Port.S1, nxt.sensor.generic.Touch)
    # Read the sensor in a loop (until interrupted).
    print("Use Ctrl-C to interrupt")
    while True:
        value = mysensor.get_sample()
        print(value)
        time.sleep(0.5)