#!/usr/bin/env python # -*- coding: utf-8 -*- import BrickPi as bp import time MOTOR_A = bp.PORT_A MOTOR_B = bp.PORT_B motors = [MOTOR_A, MOTOR_B] bp.BrickPiSetup() for motor in motors: bp.BrickPi.MotorEnable[motor] = 1 bp.BrickPiSetupSensors() bp.BrickPiUpdateValues() speed = 200 angle = 360 try: rotation_dir = 1 while True: bp.motorRotateDegree([speed] * 2, [angle * rotation_dir] * 2, motors) rotation_dir = -rotation_dir time.sleep(0.5) except KeyboardInterrupt: print('\nTerminating...') for motor in motors: bp.BrickPi.MotorSpeed[motor] = 0 bp.BrickPiUpdateValues()