Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GreenMoonArt/eab9d07b0c6bf25d7a49d11be9abec22 to your computer and use it in GitHub Desktop.
Save GreenMoonArt/eab9d07b0c6bf25d7a49d11be9abec22 to your computer and use it in GitHub Desktop.
/* YourDuino Basic Robot Kit V2 User EDitable Software Sketch
How To Page that goes with this Software Sketch:
http://arduino-info.wikispaces.com/Robot+Commands
WHAT IT DOES:
- Runs the robot motors
- Program the robot to make different moves such as Forward, SpinRight, Back etc.
- SEE the comments after "//" on each line below
- V2.20 3/27/2015 maryalice@yourduino.com
Questions: terry@yourduino.com */
Robot Commands and Editing
Now that you have built the Robot and have it running, you can learn to edit the Commands and create a newSoftware Sketch to make the Robot follow your own commands. Some of the different Commands and what they do are listed below:
Forward: Runs both motors in the forward direction
Backward: Runs both motor in a backward direction
TurnRight: Makes the left motor go forward with the right motor stopped
TurnLeft: Makes the right motor go forward with the left motor stopped
SpinRight: Runs the right motor in reverse and the left motor in forward
SpinLeft: Runs the left motor in reverse and the right motor in forward
Wait: Stops the robot for a certain length of time that you decide
Stop: Stops both motors
You can change the Robot Commands in these ways:
Speed:
Forward:
ForwardSlow, ForwardMedium, ForwardFast, ForwardMax
Backward:
BackwardSlow, BackwardMedium, BackwardFast, BackwardMax
Length of Time a Command will Run:
Time is measured in milliseconds (Ms) so 1000 Ms = 1 second, 500 Ms = 1/2 second, etc.
Order in which the Commands Occur:
You can mix and match commands to make the Robot run in many different patterns
/***************************************************************/
/*---------------------( DEFINITION AREA )---------------------*/
/***************************************************************/
/*-----( Import needed libraries )-----*/
#include <YD_MotorDriver1.h> // For control of the two DC Motors
/*-----( Declare Constants and Pin Numbers )-----*/
// NOTE: Pins 9 (Motor1) and 10 (Motor2) are predefined, unchangeable
#define Motor1A 8
#define Motor1B 7
#define Motor2C 6
#define Motor2D 5
/* Motor speed can be in the range of 200 - 400 only */
#define StartMoveSpeed 200 // Lowest Motor Speed value for start of motion
/* The section sets up the motor speeds for slow, medium, fast
The adjust numbers help make the robot run straight.
Positive numbers turn more right, negative numbers turn more left.*/
#define SlowMoveSpeed 280
#define SlowMoveAdjust 0 // Adjust to go straight: - Left + Right??
#define MediumMoveSpeed 300
#define MediumMoveAdjust 0 // Adjust to go straight: - Left + Right
#define FastMoveSpeed 350
#define FastMoveAdjust 0 // Adjust to go straight: - Left + Right
#define MaxMoveSpeed 385
#define MaxMoveAdjust 0 // Adjust to go straight: - Left + Right
/*-----( Declare objects )-----*/
YD_MotorDriver1 RobotDriver(Motor1A,Motor1B,Motor2C,Motor2D); // Set pins
/***************************************************************/
/*-----------------( SETUP AREA RUNS ONCE )--------------------*/
/***************************************************************/
void setup()
{
Serial.begin(115200); //Start the "Serial Monitor"
delay(1000);
Serial.println("YourDuino Robot Kit V2 User Editable Robot Control");
//--NOTE: Motor Pins set to OUTPUT by their libraries
RobotDriver.init(); //Start up the Robot Driver Library
}//--(end setup )---
/******************( LOOP: RUNS CONSTANTLY )********************/
void loop()
{
/***************************************************************/
/*--------------------( EDITABLE AREA )------------------------*/
/***************************************************************/
ForwardSlow(2000);
Wait(2000);
ForwardMedium(2000);
Wait(2000);
BackwardMedium(4000);
Wait(2000);
SpinRight(5000);
Wait(2000);
SpinLeft(5000);
Wait(5000);
//Now this will go back to the beginning of code in the Editable Area
/***************************************************************/
/*-----------------( END OF EDITABLE AREA )--------------------*/
/***************************************************************/
}//--(end main loop )---
/***************************************************************/
/*-------------------( MOTOR CONTROL AREA )--------------------*/
/***************************************************************/
void ForwardSlow(int howLong)
{
RobotDriver.Motor1Speed(SlowMoveSpeed + SlowMoveAdjust);
RobotDriver.Motor2Speed(SlowMoveSpeed - SlowMoveAdjust);
delay(howLong);
Stop();
}
/*---------------------------*/
void ForwardMedium(int howLong)
{
RobotDriver.Motor1Speed(MediumMoveSpeed + MediumMoveAdjust);
RobotDriver.Motor2Speed(MediumMoveSpeed - MediumMoveAdjust);
delay(howLong);
Stop();
}
/*---------------------------*/
void ForwardFast(int howLong)
{
RobotDriver.Motor1Speed(FastMoveSpeed + FastMoveAdjust);
RobotDriver.Motor2Speed(FastMoveSpeed - FastMoveAdjust);
delay(howLong);
Stop();
}
/*---------------------------*/
void ForwardMax(int howLong)
{
RobotDriver.Motor1Speed(MaxMoveSpeed + MaxMoveAdjust);
RobotDriver.Motor2Speed(MaxMoveSpeed - MaxMoveAdjust);
delay(howLong);
Stop();
}
/*---------------------------*/
void BackwardSlow(int howLong)
{
RobotDriver.Motor1Speed(- SlowMoveSpeed );
RobotDriver.Motor2Speed(- SlowMoveSpeed );
delay(howLong);
Stop();
}
/*---------------------------*/
void BackwardMedium(int howLong)
{
RobotDriver.Motor1Speed(- MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void BackwardFast(int howLong)
{
RobotDriver.Motor1Speed(- FastMoveSpeed);
RobotDriver.Motor2Speed(- FastMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void BackwardMax(int howLong)
{
RobotDriver.Motor1Speed(- MaxMoveSpeed);
RobotDriver.Motor2Speed(- MaxMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void Stop()
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(0);
}
/*---------------------------*/
void TurnLeft(int howLong)
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(MediumMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void TurnRight(int howLong)
{
RobotDriver.Motor1Speed(MediumMoveSpeed);
RobotDriver.Motor2Speed(0);
delay(howLong);
Stop();
}
/*---------------------------*/
void SpinLeft(int howLong)
{
RobotDriver.Motor1Speed(-MediumMoveSpeed);
RobotDriver.Motor2Speed( MediumMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void SpinRight(int howLong)
{
RobotDriver.Motor1Speed(MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void Wait(int howLong)
{
delay(howLong);
}
/*---------------------------*/
//*********( THE END )***********
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment