7 color = [
'?',
'BLACK',
'BLUE',
'GREEN',
'YELLOW',
'RED',
'WHITE',
'BROWN' ]
9 def _check_pressed( sn ):
10 if sn == SENSOR__NONE_:
12 return ( ok
and (( val & EV3_KEY_UP ) != 0 ))
15 return ( ok
and ( val != 0 ))
17 if __name__ ==
'__main__':
18 print 'Waiting the EV3 brick online...' 21 print '*** ( EV3 ) Hello! ***' 24 print 'Found sensors:' 25 for i
in range( SENSOR_DESC__LIMIT_ ):
27 if type_inx != SENSOR_TYPE__NONE_:
38 print ' value%d = %d' % ( ii, val )
42 print 'IR sensor is found' 44 print 'IR sensor is NOT found' 48 print 'TOUCH sensor is found, press BUTTON for EXIT...' 50 print 'TOUCH sensor is NOT found, press UP on the EV3 brick for EXIT...' 54 print 'COLOR sensor is found, reading COLOR...' 58 if not ok
or ( val < 0 )
or ( val >= len( color )):
60 sys.stdout.write(
'\r(%s)' % ( color[ val ]))
62 if _check_pressed( sn_touch ):
65 sys.stdout.write(
'\r ' )
67 if _check_pressed( sn_touch ):
71 print 'COLOR sensor is NOT found' 72 while not _check_pressed( sn_touch ):
77 print '*** ( EV3 ) Bye! ***'