Skip to content

Instantly share code, notes, and snippets.

@giljr
Created November 3, 2018 19:10
Show Gist options
  • Save giljr/383292a4fd9f6181a56f13b87db80de6 to your computer and use it in GitHub Desktop.
Save giljr/383292a4fd9f6181a56f13b87db80de6 to your computer and use it in GitHub Desktop.
TB6612FNG: Dual DC Motor Driver SparkFun Motor Driver — [email protected] peak — Ardu-Serie#49 https://medium.com/jungletronics/tb6612fng-dual-dc-motor-driver-690abd44465d
const int PWMA = 6;
const int AIN1 = 5;
const int AIN2 = 4;
void setup()
{
//set all pins as output
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMA, OUTPUT);
}
void loop()
{
//drive forward at full speed by pulling AIN1 High
//and AIN2 low, while writing a full 255 to PWMA to
//control speed
digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, LOW);
analogWrite(PWMA, 255);
//wait 1 second
delay(1000);
//Brake the motor by pulling both direction pins to
//the same state (in this case LOW). PWMA doesn't matter
//in a brake situation, but set as 0.
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, LOW);
analogWrite(PWMA, 0);
//wait 1 second
delay(1000);
//change direction to reverse by flipping the states
//of the direction pins from their forward state
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);
analogWrite(PWMA, 150);
//wait 1 second
delay(1000);
//Brake again
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, LOW);
analogWrite(PWMA, 0);
//wait 1 second
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment