summaryrefslogtreecommitdiff
path: root/robot/problems/introduction/countlines/naloga10_countLines.py
diff options
context:
space:
mode:
Diffstat (limited to 'robot/problems/introduction/countlines/naloga10_countLines.py')
-rw-r--r--robot/problems/introduction/countlines/naloga10_countLines.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/robot/problems/introduction/countlines/naloga10_countLines.py b/robot/problems/introduction/countlines/naloga10_countLines.py
new file mode 100644
index 0000000..d1a8326
--- /dev/null
+++ b/robot/problems/introduction/countlines/naloga10_countLines.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+# coding=utf-8
+
+print """
+Naloga 10:
+ Robot naj se pelje naravnost, pravokotno na crte in naj jih presteje.
+"""
+
+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' )
+
+power = 30
+
+robot.move_tank( 'on', lr_power=[power,power])
+start = time.time()
+stevec = 0
+color = -1
+while time.time()-start < 2.1:
+ c = cs.value()
+ if c!=color:
+ print c, color_table[c]
+ if c!=6 and c!=0:
+ stevec += 1
+ color = c
+robot.move_tank( 'off', brake_at_end=True )
+print "Stevilo crt:", stevec \ No newline at end of file