2016-09-14 13:33:11 -07:00
|
|
|
/*
|
|
|
|
|
* Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
|
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2016-09-14 13:33:11 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-09-14 13:33:11 -07:00
|
|
|
*/
|
|
|
|
|
|
2018-02-27 12:12:09 -08:00
|
|
|
public class MD_Example {
|
2016-09-14 13:33:11 -07:00
|
|
|
private static final short speed50 = 127;
|
|
|
|
|
private static final short speed0 = 0;
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws InterruptedException {
|
|
|
|
|
// ! [Interesting]
|
|
|
|
|
// Instantiate an I2C Motor Driver on I2C bus 0
|
|
|
|
|
upm_md.MD motors = new upm_md.MD();
|
|
|
|
|
|
|
|
|
|
// set direction to clockwise (CW) and set speed to 50%
|
|
|
|
|
System.out.println("Spin M1 and M2 at half speed for 3 seconds");
|
2016-10-18 17:02:33 -06:00
|
|
|
motors.setMotorDirections(upm_md.MD_DC_DIRECTION_T.MD_DIR_CW,
|
|
|
|
|
upm_md.MD_DC_DIRECTION_T.MD_DIR_CW);
|
2016-09-14 13:33:11 -07:00
|
|
|
motors.setMotorSpeeds(speed50, speed50);
|
|
|
|
|
Thread.sleep(3000);
|
|
|
|
|
|
|
|
|
|
// counter clockwise (CCW)
|
|
|
|
|
System.out.println("Reversing M1 and M2 for 3 seconds");
|
2016-10-18 17:02:33 -06:00
|
|
|
motors.setMotorDirections(upm_md.MD_DC_DIRECTION_T.MD_DIR_CCW,
|
|
|
|
|
upm_md.MD_DC_DIRECTION_T.MD_DIR_CCW);
|
2016-09-14 13:33:11 -07:00
|
|
|
Thread.sleep(3000);
|
|
|
|
|
|
|
|
|
|
// stop motors
|
|
|
|
|
System.out.println("Stopping motors");
|
|
|
|
|
motors.setMotorSpeeds(speed0, speed0);
|
|
|
|
|
// ! [Interesting]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|