Skip to content

Instantly share code, notes, and snippets.

@ademalp
Last active April 8, 2017 10:57
Show Gist options
  • Select an option

  • Save ademalp/fe42ba3218d6e9aac112fafb3cba840e to your computer and use it in GitHub Desktop.

Select an option

Save ademalp/fe42ba3218d6e9aac112fafb3cba840e to your computer and use it in GitHub Desktop.
Arduino L298N Pot ile İleri Geri Hız
int motorpin1 = 7;//dijital pin
int motorpin2 = 8;//dijital pin
int hizpin = 9;//pwm pin
int potpin = A0;//analog pin
void setup() {
pinMode(motorpin1, OUTPUT);
pinMode(motorpin2, OUTPUT);
pinMode(hizpin, OUTPUT);
}
void ileri(int hiz) {
digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, HIGH);
analogWrite(hizpin, hiz);
}
void geri(int hiz) {
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin1, HIGH);
analogWrite(hizpin, hiz);
}
void loop() {
int val = analogRead(potpin);
val = map(val, 0, 1023, -255, 255);
if (val > 0) {
ileri(val);
} else if (val < 0) {
geri(abs(val));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment