Created
February 4, 2018 00:33
-
-
Save slavik112211/21b7220a2aa25aeb78af20ef06ff441e to your computer and use it in GitHub Desktop.
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
const int pwm = 6 ; //initializing pin 2 as pwm | |
const int in_1 = 30 ; | |
const int in_2 =31 ; | |
//For providing logic to L298 IC to choose the direction of the DC motor | |
void setup() | |
{ | |
pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output | |
pinMode(in_1,OUTPUT) ; //Logic pins are also set as output | |
pinMode(in_2,OUTPUT) ; | |
Serial.begin(9600); | |
Serial.write("INIT"); | |
} | |
void loop() | |
{ | |
//For Clock wise motion , in_1 = High , in_2 = Low | |
digitalWrite(in_1,HIGH) ; | |
digitalWrite(in_2,LOW) ; | |
analogWrite(pwm,255) ; | |
/*setting pwm of the motor to 255 | |
we can change the speed of rotaion | |
by chaning pwm input but we are only | |
using arduino so we are using higest | |
value to driver the motor */ | |
//Clockwise for 3 secs | |
delay(1000) ; | |
Serial.write("LOOP"); | |
//For brake | |
digitalWrite(in_1,LOW) ; | |
digitalWrite(in_2,LOW) ; | |
delay(1000) ; | |
//For Anti Clock-wise motion - IN_1 = LOW , IN_2 = HIGH | |
digitalWrite(in_1,LOW) ; | |
digitalWrite(in_2,HIGH) ; | |
delay(4000) ; | |
//For brake | |
digitalWrite(in_1,LOW) ; | |
digitalWrite(in_2,LOW) ; | |
delay(1000) ; | |
//For Anti Clock-wise motion - IN_1 = LOW , IN_2 = HIGH | |
digitalWrite(in_1,HIGH) ; | |
digitalWrite(in_2,LOW) ; | |
delay(4000) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment