Created
May 10, 2017 18:25
-
-
Save bha159/6c0fb2508896a53b922343a295c5081b to your computer and use it in GitHub Desktop.
This code can be used to configure direction and speed of a bot on Arduino.
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 TxPin=10; | |
int RxPin=11; | |
int LMotor1=5; | |
int LMotor2=3; | |
int RMotor1=6; | |
int RMotor2=9; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(3,OUTPUT); | |
pinMode(5,OUTPUT); | |
pinMode(6,OUTPUT); | |
pinMode(9,OUTPUT); | |
} | |
void right() | |
{ | |
Serial.println("Moves Right"); | |
analogWrite(RMotor1,100); | |
analogWrite(RMotor2,0); | |
analogWrite(LMotor1,255); | |
analogWrite(LMotor2,0); | |
} | |
void rmotor(int dir,int spee) | |
{ | |
if(dir==1)//clockwise | |
{ | |
analogWrite(RMotor1,spee); | |
digitalWrite(RMotor2,LOW); | |
} | |
if(dir==2)//Anticlockwise | |
{ | |
digitalWrite(RMotor1,LOW); | |
analogWrite(RMotor2,spee); | |
} | |
} | |
void lmotor(int dir,int spee) | |
{ | |
if(dir==1)//clockwise | |
{ | |
digitalWrite(LMotor2,LOW); | |
analogWrite(LMotor1,spee); | |
} | |
if(dir==2)//Anticlockwise | |
{ | |
digitalWrite(LMotor1,LOW); | |
analogWrite(LMotor2,spee); | |
} | |
} | |
void mov(int spee1,int spee2) | |
{ | |
rmotor(1,spee1); | |
lmotor(2,spee2); | |
} | |
void loop() | |
{ | |
//Straight | |
//mov(227,230); | |
//Left | |
//mov(250,135); | |
//Right | |
mov(140,250); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment