File: sensors.py

package info (click to toggle)
nxt-python 3.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 812 kB
  • sloc: python: 6,857; xml: 22; makefile: 20; sh: 4
file content (19 lines) | stat: -rw-r--r-- 589 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3
"""NXT-Python example to use sensors."""
import time

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

with nxt.locator.find() as b:
    touch = b.get_sensor(nxt.sensor.Port.S1, nxt.sensor.generic.Touch)
    sound = b.get_sensor(nxt.sensor.Port.S2, nxt.sensor.generic.Sound)
    light = b.get_sensor(nxt.sensor.Port.S3, nxt.sensor.generic.Light, False)
    us = b.get_sensor(nxt.sensor.Port.S4)
    sensors = [touch, sound, light, us]

    while True:
        samples = [s.get_sample() for s in sensors]
        print(samples)
        time.sleep(0.5)