99calibrate ()
1010robot .reflectCal ()
1111
12- def left (state ):
13- if state :
14- if not mission .is_alive ():
15- minusCount ()
16- display ()
17- else :
18- abort ()
19- minusCount ()
20- display ()
21- def right (state ):
22- if state :
23- if not mission .is_alive ():
24- addCount ()
25- display ()
26- else :
27- abort ()
28- minusCount ()
29- display ()
30- def down (state ):
31- if state :
32- if not mission .is_alive ():
33- calibrate ()
34- else :
35- abort ()
36- minusCount ()
37- display ()
38- def up (state ):
39- if state :
40- if not mission .is_alive ():
41- robot .reflectCal ()
42- else :
43- abort ()
44- minusCount ()
45- display ()
46- def enter (state ):
47- if state :
48- if not mission .is_alive ():
49- run ()
50- addCount ()
51- display ()
52- else :
53- abort ()
54- minusCount ()
55- display ()
56- def backspace (state ):
57- pass
12+ def left ():
13+ robot .btn .wait_for_released ('left, right, up, down, enter' )
14+ if not mission .is_alive ():
15+ minusCount ()
16+ display ()
17+ else :
18+ abort ()
19+ minusCount ()
20+ display ()
21+ def right ():
22+ robot .btn .wait_for_released ('left, right, up, down, enter' )
23+ if not mission .is_alive ():
24+ addCount ()
25+ display ()
26+ else :
27+ abort ()
28+ minusCount ()
29+ display ()
30+ def down ():
31+ robot .btn .wait_for_released ('left, right, up, down, enter' )
32+ if not mission .is_alive ():
33+ calibrate ()
34+ else :
35+ abort ()
36+ minusCount ()
37+ display ()
38+ def up ():
39+ robot .btn .wait_for_released ('left, right, up, down, enter' )
40+ if not mission .is_alive ():
41+ robot .reflectCal ()
42+ else :
43+ abort ()
44+ minusCount ()
45+ display ()
46+ def enter ():
47+ robot .btn .wait_for_released ('left, right, up, down, enter' )
48+ if not mission .is_alive ():
49+ run ()
50+ addCount ()
51+ display ()
52+ else :
53+ abort ()
54+ minusCount ()
55+ display ()
5856
59- robot .btn .on_left = left
60- robot .btn .on_right = right
61- robot .btn .on_up = up
62- robot .btn .on_down = down
63- robot .btn .on_enter = enter
64- robot .btn .on_backspace = backspace
57+ buttonMap = {
58+ 'left' : left (),
59+ 'right' : right (),
60+ 'enter' : enter (),
61+ 'up' : up (),
62+ 'down' : down ()
63+ }
6564
66- while True :
67- robot .btn .process ()
68- loopIndex = ( loopIndex + 1 ) % 100
65+ while True :
66+ buttonMap [ robot .btn .buttons_pressed ] ()
67+ checkDrift ()
6968 displaySensor ()
70- checkDrift ()
69+ loopIndex = ( loopIndex + 1 ) % 100
0 commit comments