Skip to content

Instantly share code, notes, and snippets.

@kostyay
Created August 4, 2022 20:00
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 kostyay/563285c171d5a24934a9f58bbce9855a to your computer and use it in GitHub Desktop.
Save kostyay/563285c171d5a24934a9f58bbce9855a to your computer and use it in GitHub Desktop.
/BTS7960 motor driver sketch
int R_IS = 1;
int R_EN = 2;
int R_PWM = 3;
int L_IS = 4;
int L_EN = 5;
int L_PWM = 6;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(R_IS, OUTPUT);
pinMode(R_EN, OUTPUT);
pinMode(R_PWM, OUTPUT);
pinMode(L_IS, OUTPUT);
pinMode(L_EN, OUTPUT);
pinMode(L_PWM, OUTPUT);
digitalWrite(R_IS, LOW);
digitalWrite(L_IS, LOW);
digitalWrite(R_EN, HIGH);
digitalWrite(L_EN, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
int i;
for(i = 0; i <= 255; i= i+10){ //clockwise rotation
Serial.write("clockwise\n");
analogWrite(R_PWM, i);
analogWrite(L_PWM, 0);
delay(500);
}
delay(500);
for(i = 0; i <= 255; i= i+10){ //counter clockwise rotation
Serial.write("unclockwise\n");
analogWrite(R_PWM, 0);
analogWrite(L_PWM, i);
delay(500);
}
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment