summaryrefslogtreecommitdiff
path: root/robot/problems/introduction/printcolors/naloga09_printColors.py
blob: 0e41842038931ee3ee9c23031c6d6d0e9f504d92 (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
38
39
40
#!/usr/bin/python

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 mindstorms_widgets import *

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' )