zugaldia / adafruit-motor-hat

Android Things driver for Adafruit's DC & Stepper Motor Hat for Raspberry Pi
8 stars 7 forks source link
adafruit android android-things motor-hat raspberry-pi

Motor Hat for Android Things

Android Things driver for Adafruit's DC & Stepper Motor Hat for Raspberry Pi.

image

This is a port of the original Python library from Adafruit to Android Things. Please note this is still a work in progress, as only DC motors are supported (contributions to support stepper motors are most welcome though).

Usage

// Create a default object with no changes to I2C address or frequency
mh = new AdafruitMotorHat();

int motorIndex = 1; // Can be 1, 2, 3, 4
AdafruitDCMotor myMotor = mh.getMotor(motorIndex);

// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor.setSpeed(150);
myMotor.run(AdafruitMotorHat.FORWARD);
myMotor.run(AdafruitMotorHat.FORWARD);

// Speed up.
for (int i = 0; i < 255; i++) {
  myMotor.setSpeed(i);
  Thread.sleep((long) (0.01 * 1000));
}

// Slow down.
for (int i = 254; i >= 0; i--) {
  myMotor.setSpeed(i);
  Thread.sleep((long) (0.01 * 1000));
}
myMotor.run(AdafruitMotorHat.BACKWARD);

// Speed up.
for (int i = 0; i < 255; i++) {
  myMotor.setSpeed(i);
  Thread.sleep((long) (0.01 * 1000));
}

// Slow down.
for (int i = 254; i >= 0; i--) {
  myMotor.setSpeed(i);
  Thread.sleep((long) (0.01 * 1000));
}
myMotor.run(AdafruitMotorHat.RELEASE);
Thread.sleep((long) (1.0 * 1000));

Code

The Android Studio projects includes two modules:

This library is not available on Maven (yet).

Issues

Please open one on adafruit-motor-hat/issues.

Author

Feel free to reach out on Twitter.