Skip to content

Commit e79121f

Browse files
committed
Change turn method of left/right on motor_move() and add the test case of it
1 parent 2a01c9c commit e79121f

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

neopia/neosoco.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,11 @@ def motor_move(self, direction: str):
435435
self.write(Neosoco.LEFT_MOTOR, self._MOTOR_DIR['backward']+self._MOTOR_PERCENT_CVT['60'])
436436
self.write(Neosoco.RIGHT_MOTOR, self._MOTOR_DIR['backward']+self._MOTOR_PERCENT_CVT['60'])
437437
elif direction.lower() =='left':
438-
self.write(Neosoco.LEFT_MOTOR, 0)
438+
self.write(Neosoco.LEFT_MOTOR, self._MOTOR_DIR['backward']+self._MOTOR_PERCENT_CVT['60'])
439439
self.write(Neosoco.RIGHT_MOTOR, self._MOTOR_DIR['forward']+self._MOTOR_PERCENT_CVT['60'])
440440
elif direction.lower() =='right':
441441
self.write(Neosoco.LEFT_MOTOR, self._MOTOR_DIR['forward']+self._MOTOR_PERCENT_CVT['60'])
442-
self.write(Neosoco.RIGHT_MOTOR, 0)
442+
self.write(Neosoco.RIGHT_MOTOR, self._MOTOR_DIR['backward']+self._MOTOR_PERCENT_CVT['60'])
443443
elif direction.lower() =='stop':
444444
self.write(Neosoco.LEFT_MOTOR, 0)
445445
self.write(Neosoco.RIGHT_MOTOR, 0)

test.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,23 @@
1818
# n.set_value('out1', 0)
1919

2020
# case4) Move forth and back during 1s and stop
21-
n.motor_move('forward')
22-
wait(500)
23-
n.motor_move('backward')
24-
wait(500)
25-
n.motor_move('stop')
21+
# n.motor_move('forward')
22+
# wait(500)
23+
# n.motor_move('backward')
24+
# wait(500)
25+
# n.motor_move('stop')
26+
27+
# case5) Moving cotrol by direction keys on the keyboard
28+
while True:
29+
key = Keyboard.read()
30+
31+
if key == Keyboard.UP:
32+
n.motor_move('forward')
33+
elif key == Keyboard.DOWN:
34+
n.motor_move('backward')
35+
elif key == Keyboard.LEFT:
36+
n.motor_move('left')
37+
elif key == Keyboard.RIGHT:
38+
n.motor_move('right')
39+
elif key == ' ':
40+
n.motor_move('stop')

0 commit comments

Comments
 (0)