-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTrialApp.py
More file actions
43 lines (36 loc) · 1.41 KB
/
TrialApp.py
File metadata and controls
43 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# App
#
# Copyright (c) 2014 Charles Weir. Shared under the MIT Licence.
import sys, os # Python path kludge - omit these 2 lines if BrickPython is installed.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))))
from BrickPython.TkApplication import TkApplication
from BrickPython.Sensor import Sensor, TouchSensor, LightSensor,\
UltrasonicSensor
import logging
class App(TkApplication):
'''Application to do stuff.
'''
def __init__(self):
settings = {'1': LightSensor, '2': TouchSensor, '3': UltrasonicSensor }
TkApplication.__init__(self, settings)
self.root.wm_title("Trial running")
for c in "ABCD":
self.motor(c).zeroPosition()
self.addActionCoroutine(self.motor(c).runAtConstantSpeed(180))
for c in settings:
self.addSensorCoroutine(self.showChanges(c))
def showChanges(self, sensorId):
sensor = self.sensor(sensorId)
while True:
for i in sensor.waitForChange(): yield
print sensor
def showSensorValues(self, sensorId):
sensor = self.sensor(sensorId)
while True:
for i in self.waitMilliseconds(1000): yield
print sensor
if __name__ == "__main__":
logging.basicConfig(format='%(message)s', level=logging.DEBUG) # All log messages printed to console.
logging.info( "Starting" )
app = App()
app.mainloop()