Last active
August 3, 2016 16:47
-
-
Save GreenMoonArt/58067ddb21d52ff74d2d5938480869e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Install motor driver library: http://yourduino.com/docs/A_YD_Motor1.zip | |
/* YourDuino.com Example Software Sketch | |
MotorDriverDEV | |
YD_MotorDriver1 Library Test | |
source: https://arduino-info.wikispaces.com/YourDuino-Basic-Robot-Kit-Software-Version2 | |
terry@yourduino.com | |
Note: If you have the motors connected properly you should first see the right-hand motor go forward and then reverse, | |
followed by the left-hand motor going forward and then reverse. If a motor is rotating in the wrong direction, | |
check the wiring as shown in the photos, and if necessary reverse the red and black wires where they are connected | |
to the motor driver terminal block. | |
*/ | |
/*-----( Import needed libraries )-----*/ | |
#include <YD_MotorDriver1.h> | |
/*-----( Declare Constants )-----*/ | |
// NOTE: Pins 9 (Motor1) and 10 (Motor2) are predefined, unchangeable | |
#define Motor1A 8 | |
#define Motor1B 7 | |
#define Motor2C 6 | |
#define Motor2D 5 | |
#define RampDelay 100 | |
/*-----( Declare objects )-----*/ | |
YD_MotorDriver1 RobotDriver(Motor1A,Motor1B,Motor2C,Motor2D); | |
//YD_MotorDriver1 RobotDriver(); | |
/*-----( Declare Variables )-----*/ | |
void setup() /*----( SETUP: RUNS ONCE )----*/ | |
{ | |
Serial.begin(115200); | |
Serial.println("YourDuino MotorDriver1 Ramp Up / Down Test"); | |
RobotDriver.init(); | |
}/*--(end setup )---*/ | |
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/ | |
{ | |
delay(2000); // Give time to put the robot down! | |
Serial.println("Motor 1 0..+400"); | |
for (int i = 0; i <= 400; i = i + 10) | |
{ | |
RobotDriver.Motor1Speed(i); | |
Serial.print(i,DEC); | |
Serial.print(" "); | |
delay(RampDelay); | |
} | |
Serial.println(); | |
delay(500); | |
Serial.println("Motor 1 +400..0..-400"); | |
for (int i = 400; i >= -400; i = i - 10) | |
{ | |
RobotDriver.Motor1Speed(i); | |
Serial.print(i,DEC); | |
Serial.print(" "); | |
delay(RampDelay); | |
} | |
Serial.println(); | |
delay(500); | |
Serial.println("Motor 1 -400..0"); | |
for (int i = -400; i <= 0; i = i + 10) | |
{ | |
RobotDriver.Motor1Speed(i); | |
Serial.print(i,DEC); | |
Serial.print(" "); | |
delay(RampDelay); | |
} | |
Serial.println(); | |
delay(500); | |
/*----( Ramp Motor2 Up and Down both directions )-------*/ | |
Serial.println("Motor 2 0+"); | |
for (int i = 0; i <= 400; i = i + 10) | |
{ | |
RobotDriver.Motor2Speed(i); | |
Serial.print(i,DEC); | |
Serial.print(" "); | |
delay(RampDelay); | |
} | |
Serial.println(); | |
delay(500); | |
Serial.println("Motor 2 +-"); | |
for (int i = 400; i >= -400; i = i - 10) | |
{ | |
RobotDriver.Motor2Speed(i); | |
Serial.print(i,DEC); | |
Serial.print(" "); | |
delay(RampDelay); | |
} | |
Serial.println(); | |
delay(500); | |
Serial.println("Motor 2 -0"); | |
for (int i = -400; i <= 0; i = i + 10) | |
{ | |
RobotDriver.Motor2Speed(i); | |
Serial.print(i,DEC); | |
Serial.print(" "); | |
delay(RampDelay); | |
} | |
Serial.println(); | |
delay(500); | |
}/* --(end main loop )-- */ | |
/*-----( Declare User-written Functions )-----*/ | |
/* ( THE END ) */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment