Created
January 9, 2018 04:35
-
-
Save elktros/99e3346bc44d02397f1a1ede9db5fbee to your computer and use it in GitHub Desktop.
Arduino code for controlling DC Motor with L298N Motor Driver.
This file contains 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 mot1 = 8; | |
int mot2 = 9; | |
int en1 = 10; | |
int dir = 6; | |
bool state = true; | |
int nob = A0; | |
int val=0; | |
void setup() | |
{ | |
pinMode(mot1,OUTPUT); | |
pinMode(mot2,OUTPUT); | |
pinMode(en1,OUTPUT); | |
pinMode(dir,INPUT_PULLUP); | |
} | |
void loop() | |
{ | |
val = analogRead(nob); | |
analogWrite(en1, val / 4); | |
if(digitalRead(dir)==LOW) | |
{ | |
state=!state; | |
while(dir==LOW); | |
delay(300); | |
} | |
if(state) | |
{ | |
digitalWrite(mot1,HIGH); | |
digitalWrite(mot2,LOW); | |
} | |
else | |
{ | |
digitalWrite(mot1,LOW); | |
digitalWrite(mot2,HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment