Last active
April 8, 2017 10:57
-
-
Save ademalp/fe42ba3218d6e9aac112fafb3cba840e to your computer and use it in GitHub Desktop.
Arduino L298N Pot ile İleri Geri Hız
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
| 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