Created
February 14, 2020 01:08
-
-
Save buzztiaan/a88ae312532fa675c82f2dbd1ba4c3b3 to your computer and use it in GitHub Desktop.
arduino DRV8833 code
This file contains hidden or 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
// 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