This program makes the robot move forwards and then backwards using LEGO Education SPIKE App Python.
from spike import PrimeHub, LightMatrix, Button, StatusLight, ForceSensor, MotionSensor, Speaker, ColorSensor, App, DistanceSensor, Motor, MotorPair from spike.control import wait_for_seconds, wait_until, Timer from math import * hub = PrimeHub() motor_pair = MotorPair('A', 'B') # Set the motor ports in the motor_pair. motor_pair.set_default_speed(50) # Set the default speed of the the motor_pair. motor_pair.set_motor_rotation(17.6, 'cm') # Set the distance that the robot travel for one rotation of its wheels. The value 17.6 comes from # the diameter of the wheel (5.6cm) multiplied by "π" (3.14). motor_pair.move(40,'cm', 0, 50) # Start moving for 40cm with NO Steering '0' with 50% speed. motor_pair.move(40,'cm', 0, -50) # Start moving backward for 40cm with NO Steering '0' with 50% speed. -50 for speed means: rotate with 50% seed backward. raise SystemExit # Close the program.
How to open?
Download- #s3c8dj
- 11 Mar 2021