|
| 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 | + |
| 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 |
0 commit comments