Skip to content

Instantly share code, notes, and snippets.

@hapiel
Created April 17, 2024 17:53
Show Gist options
  • Save hapiel/1fdf01f2a565c1b603fcd288a8e425fb to your computer and use it in GitHub Desktop.
Save hapiel/1fdf01f2a565c1b603fcd288a8e425fb to your computer and use it in GitHub Desktop.
// Arduino code by Daniel Simu
// for https://www.youtube.com/watch?v=D7hkFh4uhMo&t=1250s
// pins
#define POTENTIOMETER A0 // to middle pin of potentionmeter, the other two go to GND and VCC (5v)
#define PWM_R 3 // to BTS7960
#define PWM_L 5 // to BTS7960
void setup() {
}
void loop() {
// range 0 - 512
int pot = analogRead(POTENTIOMETER) / 2;
// turn right
if (pot > 256){
analogWrite(PWM_R, pot - 256);
analogWrite(PWM_L, 0);
}
// turn left
else if (pot < 256){
analogWrite(PWM_R, 0);
analogWrite(PWM_L, (pot - 255) * -1);
}
// don't turn if exactly in middle
else {
analogWrite(PWM_R, 0);
analogWrite(PWM_L, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment