Skip to content

Instantly share code, notes, and snippets.

@buzztiaan
Created February 14, 2020 01:08
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 buzztiaan/a88ae312532fa675c82f2dbd1ba4c3b3 to your computer and use it in GitHub Desktop.
Save buzztiaan/a88ae312532fa675c82f2dbd1ba4c3b3 to your computer and use it in GitHub Desktop.
arduino DRV8833 code
// connections to DRV8833
int AIN1pin = 9;
int AIN2pin = 10;
int BIN1pin = 14;
int BIN2pin = 15;
#define motorA 1
#define motorB 2
void configureMotor ( int motor , int speed ) {
// speed = 128 = stop
// speed = 0 = fullspeed backwards
// speed = 256 = fullspeed forwards
int IN1;
int IN2;
if (motor == motorA) {
IN1 = AIN1pin;
IN2 = AIN2pin;
} else {
IN1 = BIN1pin;
IN2 = BIN2pin;
}
if (speed == 128){
digitalWrite(IN1, 1);
digitalWrite(IN2, 1);
}
if (speed < 128) {
digitalWrite(IN1, 1);
analogWrite(IN2, 256-map(speed,0,127,0,255));
}
if (speed > 128) {
digitalWrite(IN2, 1);
analogWrite(IN1, map(speed,129,255,0,255));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment