GithubHelp home page GithubHelp logo

roshanrajaratnam / adafruit-motor-hat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zugaldia/adafruit-motor-hat

0.0 1.0 0.0 104 KB

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

Java 88.41% Kotlin 11.59%

adafruit-motor-hat's Introduction

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

  • Basic 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);
  • Move 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));
}
  • Move backwards:
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));
}
  • Release:
myMotor.run(AdafruitMotorHat.RELEASE);
Thread.sleep((long) (1.0 * 1000));

Code

The Android Studio projects includes two modules:

  • The lib module has the code you'll want to include on your own projects. It's a port of the original Python library using Android's com.google.android.things.pio.I2cDevice under the hood.

  • The app module shows a simple example of how to use the library (see the video linked above to see the MainActivity running).

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.