-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeVeMotor.ino
223 lines (190 loc) · 4.54 KB
/
NodeVeMotor.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* gungor 26/01/2019
*/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "3f496242185f4caca14d899a6741f6e5";
// Your WiFi credentials.
char ssid[] = "TD"; //YourNetworkName
char pass[] = "tahadem34"; //YourPassword
BlynkTimer timer;
const byte L298N_A_pin = D1; // GPI05
const byte L298N_A_In1_pin = D2; //GPI04
const byte L298N_A_In2_pin = D3; //GPI0
const byte L298N_B_In3_pin = D4; // GPI02
const byte L298N_B_In4_pin = D5; // GPIO14
const byte L298N_B_pin = D6; //GPI12
const byte Led1_pin = D7; //GPIO13 // Sol Sinyal
const byte Led2_pin = D8; //GPIO15 // Sag Sinyal
const byte Led3_pin = D9; //GPIO3 // On Far
const byte Led4_pin = D10; //GPI01 // Arka Lamba
const byte Korna_pin = D0; //GPI016 //Korna
WidgetLED led1(V1); //Sol
WidgetLED led2(V2); //Sag
WidgetLED led3(V3); //A1
WidgetLED led4(V4); //B1
WidgetLED led5(V5); //Far
WidgetLED led6(V6); //Arka
WidgetLED led7(V7); //A2
WidgetLED led8(V8); //B2
byte SolSinyal = 0;
byte SagSinyal = 0;
byte ArkaLamba = 0;
/*
* blynk ekranı
* V0 joystick,
* v1,v2, v3, v4,v5,v6,v7,v8 Led
* v10 button push
* v11 button switch
*/
BLYNK_WRITE(V10) {
/* Korna*/
digitalWrite(Korna_pin,param.asInt());
}
BLYNK_WRITE(V11) {
/* On Far*/
digitalWrite(Led3_pin,param.asInt());
}
void motorSpeed(int prmA, byte prmA1, byte prmA2, int prmB, byte prmB1, byte prmB2)
{
analogWrite(L298N_A_pin,prmA);
analogWrite(L298N_B_pin,prmB);
digitalWrite(L298N_A_In1_pin,prmA1);
digitalWrite(L298N_A_In2_pin,prmA2);
digitalWrite(L298N_B_In3_pin,prmB1);
digitalWrite(L298N_B_In4_pin,prmB2);
if (prmA1==LOW)
led3.off();
else
led3.on();
if (prmA2==LOW)
led7.off();
else
led7.on();
if (prmB1==LOW)
led4.off();
else
led4.on();
if (prmB2==LOW)
led8.off();
else
led8.on();
}
BLYNK_WRITE(V0) {
int x = param[0].asInt();
int y = param[1].asInt();
// x = -2 -1 0 1 2
// Y = -2 -1 0 1 2
if (y>=0)
{
ArkaLamba = 0;
digitalWrite(Led4_pin,LOW);
}
else
{
ArkaLamba = 1;
SolSinyal = 1;
SagSinyal = 1;
digitalWrite(Led1_pin,HIGH);
digitalWrite(Led2_pin,HIGH);
digitalWrite(Led4_pin,HIGH);
}
if ((x==0) && (y==0)) // duruyor
{
motorSpeed(0,LOW,LOW,0,LOW,LOW);
SolSinyal = 0;
SagSinyal = 0;
digitalWrite(Led1_pin,LOW);
digitalWrite(Led2_pin,LOW);
}
else if ((x==0) && (y>0)) // düz ileri
{
if (y==1){ motorSpeed(900,HIGH,LOW,900,HIGH,LOW); }
else { motorSpeed(1023,HIGH,LOW,1023,HIGH,LOW); }
SolSinyal = 0;
SagSinyal = 0;
digitalWrite(Led1_pin,LOW);
digitalWrite(Led2_pin,LOW);
}
else if ((y==0) && (x>0))// Tam Sag donuş
{
motorSpeed(900,HIGH,LOW,900,LOW,HIGH);
SagSinyal = 1;
digitalWrite(Led2_pin,HIGH);
}
else if ((y>0) && (x>0))// Sag donuş
{
motorSpeed(1023,HIGH,LOW,900,LOW,LOW);
SagSinyal = 1;
digitalWrite(Led2_pin,HIGH);
}
else if ((y==0) && (x<0))// Tam sola donuş
{
motorSpeed(900,LOW,HIGH,900,HIGH,LOW);
SolSinyal = 1;
digitalWrite(Led1_pin,HIGH);
}
else if ((y>0) && (x<0))// Sola donuş
{
motorSpeed(900,LOW,LOW,1023,HIGH,LOW);
SolSinyal = 1;
digitalWrite(Led1_pin,HIGH);
}
if ((y<0) && (x<0))// Sola geri
motorSpeed(900,LOW,LOW,1023,LOW,HIGH);
else if ((y<0) && (x>0))// Sag geri
motorSpeed(1023,LOW,HIGH,900,LOW,LOW);
else if ((y<0) && (x==0))// tam geri
motorSpeed(900,LOW,HIGH,900,LOW,HIGH);
}
void setup() {
Serial.begin(115200);
pinMode(L298N_A_In1_pin,OUTPUT);
pinMode(L298N_A_In2_pin,OUTPUT);
pinMode(L298N_B_In3_pin,OUTPUT);
pinMode(L298N_B_In4_pin,OUTPUT);
digitalWrite(L298N_A_In1_pin,LOW);
digitalWrite(L298N_A_In2_pin,LOW);
digitalWrite(L298N_B_In3_pin,LOW);
digitalWrite(L298N_B_In4_pin,LOW);
pinMode(Led1_pin,OUTPUT);
pinMode(Led2_pin,OUTPUT);
pinMode(Led3_pin,OUTPUT);
pinMode(Led4_pin,OUTPUT);
digitalWrite(Led1_pin,LOW);
digitalWrite(Led2_pin,LOW);
digitalWrite(Led3_pin,LOW);
digitalWrite(Led4_pin,LOW);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendTemps);
}
void sendTemps()
{
if (SolSinyal==1)
digitalWrite(Led1_pin,!digitalRead(Led1_pin));
if (SagSinyal==1)
digitalWrite(Led2_pin,!digitalRead(Led2_pin));
if (ArkaLamba==1)
digitalWrite(Led4_pin,!digitalRead(Led4_pin));
if (digitalRead(Led1_pin)==HIGH)
led1.on();
else
led1.off();
if (digitalRead(Led2_pin)==HIGH)
led2.on();
else
led2.off();
if (digitalRead(Led3_pin)==HIGH)
led5.on();
else
led5.off();
if (digitalRead(Led4_pin)==HIGH)
led6.on();
else
led6.off();
}
void loop() {
Blynk.run();
timer.run();
}