Skip to content

Instantly share code, notes, and snippets.

@arjo129
Last active December 29, 2015 01:49
Show Gist options
  • Save arjo129/7596444 to your computer and use it in GitHub Desktop.
Save arjo129/7596444 to your computer and use it in GitHub Desktop.
For SSIS Robotics Club
int pwm_a = 3; //PWM control for motor outputs 1 and 2 is on digital pin 3
int pwm_b = 11; //PWM control for motor outputs 3 and 4 is on digital pin 11
int dir_a = 12; //direction control for motor outputs 1 and 2 is on digital pin 12
int dir_b = 13; //direction control for motor outputs 3 and 4 is on digital pin 13
int val = 0;
void setup(){
pinMode(pwm_a, OUTPUT);
pinMode(pwm_b, OUTPUT);
pinMode(dir_b, OUTPUT);
pinMode(dir_a, OUTPUT);
}
void forward() //full speed forward
{
digitalWrite(dir_a, HIGH); //Reverse motor direction, 1 high, 2 low
digitalWrite(dir_b, HIGH); //Reverse motor direction, 3 low, 4 high
analogWrite(pwm_a, 255); //set both motors to run at (100/255 = 39)% duty cycle
analogWrite(pwm_b, 255);
}
void backward() //full speed backward
{
digitalWrite(dir_a, LOW); //Set motor direction, 1 low, 2 high
digitalWrite(dir_b, LOW); //Set motor direction, 3 high, 4 low
analogWrite(pwm_a, 255); //set both motors to run at 100% duty cycle (fast)
analogWrite(pwm_b, 255);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment