summaryrefslogtreecommitdiff
path: root/robot/problems/introduction/printcolors/naloga09_printColors.py
diff options
context:
space:
mode:
Diffstat (limited to 'robot/problems/introduction/printcolors/naloga09_printColors.py')
-rw-r--r--robot/problems/introduction/printcolors/naloga09_printColors.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/robot/problems/introduction/printcolors/naloga09_printColors.py b/robot/problems/introduction/printcolors/naloga09_printColors.py
new file mode 100644
index 0000000..59dfdb0
--- /dev/null
+++ b/robot/problems/introduction/printcolors/naloga09_printColors.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+# coding=utf-8
+
+print ("""
+Naloga 9:
+ Robot naj se pelje cez barvne crte in na zaslon izpise barvo, ki jo zazna s svetlobnim senzorjem.
+ Value Color
+ 0 none
+ 1 black
+ 2 blue
+ 3 green
+ 4 yellow
+ 5 red
+ 6 white
+ 7 brown
+""")
+import sys
+sys.path.append('/home/user/codeq')
+import time
+from ev3dev import *
+from mindstorms_widgets import mindstorms_widgets
+
+color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown']
+
+#cs = color_sensor()
+#assert cs.connected
+#cs.mode = 'COL-COLOR' # values: 0-7 see the scale above
+
+robot = mindstorms_widgets()
+robot.connect_motor( 'left' )
+robot.connect_motor( 'right' )
+robot.connect_sensor( 'color' )
+
+robot.move_steering( 'on')
+start = time.time()
+color = -1
+while time.time()-start < 2.1:
+ c = robot.color_sensor_measure('color')
+ if c!=color:
+ print( c, color_table[c])
+ color = c
+robot.move_steering( 'off' )