Skip to content

Commit b988ed1

Browse files
committed
Initial commit
1 parent f5ce6e8 commit b988ed1

10 files changed

Lines changed: 837 additions & 0 deletions

File tree

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SB Components Motor-Shield Java API
2+
3+
Disclaimer : Not the offical API for this shield, the original is on python and in the link : [Original API](https://github.com/sbcshop/MotorShield)
4+
If you want the original manual go here : [Manual
5+
](https://github.com/sbcshop/MotorShield/blob/master/Maker_Sphere_Manual.pdf)
6+
7+
![](https://cdn.shopify.com/s/files/1/1217/2104/products/motor_shield_a_720_660_1800x1800.png?v=1528533987)
8+
9+
10+
## How it works
11+
```java
12+
Motor m1 = Motors.MOTOR_1; // Get the motor Can be MOTOR_2 , MOTOR_3 or MOTOR_4
13+
14+
m1.forward(100); //Tell the motor to go forward at the speed of 100% (Anything higher will be the same)
15+
m1.stop(); //Tell the motor to stop, it will set his speed to 0
16+
m1.reverse(100); // Tell the motor to go in reverse at the speed of 100%
17+
18+
m1.unBound(); //Unbound the motor, it will released all the pin and can be recreate to work
19+
```
20+
Here you have the basics of the API, you can create more complexe one :
21+
```java
22+
Motor m1 = Motors.MOTOR_1;
23+
Motor m2 = Motors.MOTOR_2;
24+
Motor m3 = Motors.MOTOR_3;
25+
Motor m4 = Motors.MOTOR_4;
26+
//Create all motors
27+
28+
LinkedMotors all = new LinkedMotors(m1, m2, m3, m4); // Create a list with all the motors
29+
30+
all.forward(100); // Tell all motors to move forward at a speed of 100%
31+
all.stop(); //Tell all motors to stop, it will set their speed to 0
32+
all.reverse(100); // Tell all motors to go on reverse at a speed of 100%
33+
```
34+
or
35+
```java
36+
Motor m1 = Motors.MOTOR_1;
37+
Motor m2 = Motors.MOTOR_2;
38+
Motor m3 = Motors.MOTOR_3;
39+
Motor m4 = Motors.MOTOR_4;
40+
//Create all motors
41+
42+
InvertedMotors motorsList = new InvertedMotors();
43+
motorsList.addReverse(m2);
44+
motorsList.addReverse(m3);
45+
motorsList.addGoodWay(m1);
46+
motorsList.addGoodWay(m4);
47+
// Create a list with all the motors
48+
49+
motorsList.forward(100); // Tell all motors m1 and m4 to go forward and tell m2 and m3 to go on reverse
50+
motorsList.stop(); //Tell all motors to stop, it will set their speed to 0
51+
motorsList.reverse(100); // Tell all motors m1 and m4 to go on reverse and tell m2 and m3 to go forward
52+
```
53+
The last exemple can be usefull if you have a 4 motor setup and all the motors cannot be on the same direction

build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'fr.pa1007'
6+
version '1.0'
7+
8+
sourceCompatibility = 1.8
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
testCompile group: 'junit', name: 'junit', version: '4.12'
16+
compile group: 'com.pi4j', name: 'pi4j-core', version: '1.2'
17+
}

gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'motorapi'
2+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package fr.pa1007.motor.api;
2+
3+
import com.pi4j.io.gpio.*;
4+
5+
/**
6+
* The arrows are the arrow on the top of the board can activate them and deactivate them
7+
* <br>
8+
* See their Python API here : <a href="https://github.com/sbcshop/MotorShield">https://github.com/sbcshop/MotorShield</a>
9+
*
10+
* @author pa1007
11+
*/
12+
public class Arrow {
13+
14+
/**
15+
* The Front arrow ( Facing the power entry)
16+
*/
17+
public static final Arrow MOTOR_4 = new Arrow(RaspiPin.GPIO_23, "Motor 4");
18+
19+
20+
/**
21+
* The right arrow ( Facing the 40 pins)
22+
*/
23+
public static final Arrow MOTOR_3 = new Arrow(RaspiPin.GPIO_24, "Motor 3");
24+
25+
/**
26+
* The back arrow ( Facing the detection unit)
27+
*/
28+
public static final Arrow MOTOR_2 = new Arrow(RaspiPin.GPIO_25, "Motor 2");
29+
30+
/**
31+
* The left arrow ( Facing the motors connectors)
32+
*/
33+
public static final Arrow MOTOR_1 = new Arrow(RaspiPin.GPIO_27, "Motor 1");
34+
35+
private GpioPinDigitalOutput output;
36+
37+
/**
38+
* Protected constructor
39+
*
40+
* @param pin the pin of the arrow to turn it on
41+
* @param name the name of the connector
42+
*/
43+
protected Arrow(Pin pin, String name) {
44+
GpioController gpio = GpioFactory.getInstance();
45+
this.output = gpio.provisionDigitalOutputPin(pin, name);
46+
}
47+
48+
public void on() {
49+
output.setState(PinState.HIGH);
50+
}
51+
52+
public void off() {
53+
output.setState(PinState.LOW);
54+
}
55+
56+
}

0 commit comments

Comments
 (0)