print('Rotating') motionControl.rotate(-10) # elif event.ev_type == 'Key' and event.code == 'BTN_WEST1' and event.state == 0: # accel = mpu9250.readAccel() # print("ax=\t", accel['x'], "\tay=\t", accel['y'], "\taz=\t", accel['z']) # elif event.ev_type == 'Key' and event.code == 'BTN_WEST2' and event.state == 0: # gyro = mpu9250.readGyro() # print("gx=\t", gyro['x'], "\tgy=\t", gyro['y'], "\tgz=\t", gyro['z']) # elif event.ev_type == 'Key' and event.code == 'BTN_WEST3' and event.state == 0: # mag = mpu9250.readMagnet() # print("mx=\t", mag['x'], "\tmy=\t", mag['y'], "\tmz=\t", mag['z']) elif event.ev_type == 'Key' and event.code == 'BTN_TL' and event.state == 0: servoAngle += 10 servoAngle = servo.rotate(servoAngle) print("Servo Motor Angle:", servoAngle) elif event.ev_type == 'Key' and event.code == 'BTN_TR' and event.state == 0: servoAngle -= 10 servoAngle = servo.rotate(servoAngle) print("Servo Motor Angle:", servoAngle) elif event.ev_type == 'Key' and event.code == 'BTN_WEST6' and event.state == 0: distance = ultrasonicSensorFront.getDistance() print("Measured Distance = %.1f cm in Front" % (distance)) elif event.ev_type == 'Key' and event.code == 'BTN_WEST7' and event.state == 0: distance = ultrasonicSensorBack.getDistance() print("Measured Distance = %.1f cm in Back" % (distance)) except KeyboardInterrupt: motionControl.cleanup() servo.clean() ultrasonicSensorFront.clean() ultrasonicSensorBack.clean()