summaryrefslogtreecommitdiff
path: root/robot/problems/introduction/countlines/naloga10_countLines.py
blob: d1a8326e818d26a30e4c1debe03a814c2b388362 (plain)
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
#!/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