-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_controlled.ino
120 lines (101 loc) · 2.56 KB
/
app_controlled.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// This code is for NodeMCU and blynk app configuration
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "dF8BaHiYDmHu1txHEJSWZuwUZyCnYmOU";
char ssid[] = "k27";
char pass[] = "987654321";
int motorR1= D0;
int motorR2=D1;
int motorL1=D2;
int motorL2=D3;
int EN1=D5;
int EN2=D6;
BLYNK_WRITE(V1)
{
int x = param[0].asInt();
Serial.println(x);
int y= param[1].asInt();
Serial.println(y);
movecontrol(x,y);
}
void setup()
{
Blynk.begin(auth, ssid, pass);
pinMode(EN1,OUTPUT);
pinMode(EN2,OUTPUT);
pinMode(motorL1,OUTPUT);
pinMode(motorL2,OUTPUT);
pinMode(motorR1,OUTPUT);
pinMode(motorR2,OUTPUT);
digitalWrite(EN1,HIGH);
digitalWrite(EN2,HIGH);
Serial.begin(115200);// put your setup code here, to run once:
}
void movecontrol(int x,int y)
{
if(x > 400 && x < 600 && y ==1000 )
{
forward();
Serial.println("Moving forward");
}
else if(x > 400 && x < 600 && y ==0 )
{
backward();
Serial.println("Moving Backward");
}
else if(x ==1000 && y > 400 && y<600 )
{
right();
Serial.println("Moving Right");
}
else if(x ==0 && y > 400 && y<600 )
{
left();
Serial.println("Moving Left");
}
else if( (x==500) and (y==500) )
{
nomove();
Serial.println("Movement Stopped");
}
}
void loop()
{
Blynk.run();
}
void forward()
{
digitalWrite(motorL1,LOW); //Left part moving anticlockwise
digitalWrite(motorL2,HIGH);
digitalWrite(motorR1,HIGH); //Right part moving clockwise
digitalWrite(motorR2,LOW);
}
void backward()
{
digitalWrite(motorL1,HIGH); //Left part moving clockwise
digitalWrite(motorL2,LOW);
digitalWrite(motorR1,LOW); //Right part moving anticlockwise
digitalWrite(motorR2,HIGH);
}
void right()
{
digitalWrite(motorL1,LOW); //Left part moving anticlockwise
digitalWrite(motorL2,HIGH);
digitalWrite(motorR1,LOW); //Right part not moving
digitalWrite(motorR2,LOW);
}
void left()
{
digitalWrite(motorL1,LOW); //Left part not moving
digitalWrite(motorL2,LOW);
digitalWrite(motorR1,HIGH); //Right part moving clockwise
digitalWrite(motorR2,LOW);
}
void nomove()
{
digitalWrite(motorL1,LOW); //Left part not moving
digitalWrite(motorL2,LOW);
digitalWrite(motorR1,LOW); //Right part not moving
digitalWrite(motorR2,LOW);
}