root/Lego/python/sensors.py

Revision 8, 0.8 kB (checked in by Jan-Klaas Kollhof, 3 years ago)

updated SVN keywords

  • Property svn:executable set to *
  • Property svn:keywords set to Date Author LastChangedDate
Line 
1#!/usr/bin/env python
2"""
3Simple script to display sensor values.
4
5author: Jan-Klaas Kollhof
6last changed by: $LastChangedBy$
7last changed date: $Date$
8revision: $Revision$
9"""
10
11import nxt.locator
12from nxt.sensor import *
13
14
15def displaySensors():
16    sock = nxt.locator.find_one_brick()
17    brick = sock.connect()
18   
19    touch = TouchSensor(brick, PORT_1)
20    sound = SoundSensor(brick, PORT_2)
21    light =  LightSensor(brick, PORT_3)
22    sonic = UltrasonicSensor(brick, PORT_4)
23    try:
24        while True:
25            values =  (touch.get_sample(), sound.get_sample(), light.get_sample(), sonic.get_sample())
26            print "touch:%s sound: %03d light:%03d sonic:%03d" % values
27    except:
28        pass
29    finally:
30        sock.close()
31
32
33if __name__ == "__main__":
34    displaySensors()
Note: See TracBrowser for help on using the browser.