-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluetooth_car_control
117 lines (100 loc) · 2.4 KB
/
bluetooth_car_control
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
#include <SoftwareSerial.h>
#define rxPin 3
#define txPin 4
SoftwareSerial bluetoothSerial(rxPin, txPin); // (rx, tx)
char data;
// Motor Pin Bağlantıları
int motorA1 = 6; // Motor A'nın yön pini 1
int motorA2 = 7; // Motor A'nın yön pini 2
int motorB1 = 8; // Motor B'nin yön pini 1
int motorB2 = 9; // Motor B'nin yön pini 2
int pwm1 = 5;
int pwm2 =10;
// Fonksiyonlar
void ileriGit() {
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
analogWrite(pwm1, 127);
analogWrite(pwm2, 127);
}
void geriGit() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, HIGH);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, HIGH);
analogWrite(pwm1, 127);
analogWrite(pwm2, 127);
}
void sagaDon() {
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, HIGH);
analogWrite(pwm1, 127);
analogWrite(pwm2, 127);
}
void solaDon() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, HIGH);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
analogWrite(pwm1, 127);
analogWrite(pwm2, 127);
}
void dur() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, LOW);
}
void setup() {
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
pinMode(rxPin, INPUT); // Bluetooth modül RX pinini giriş olarak ayarla
pinMode(txPin, OUTPUT); // Bluetooth modül TX pinini çıkış olarak ayarla
Serial.begin(9600);
Serial.println("Merhaba Seri Port");
bluetoothSerial.begin(9600);
bluetoothSerial.println("Merhaba Bluetooth");
}
void loop() {
if (bluetoothSerial.available()) {
data = bluetoothSerial.read();
Serial.println(data);
if (data == '3') {
ileriGit();
delay(2000);
dur();
delay(1000);
} else if (data == '4') {
geriGit();
delay(2000);
dur();
delay(1000);
} else if (data == '1') {
sagaDon();
delay(50);
dur();
delay(1000);
} else if (data == '2') {
solaDon();
delay(50);
dur();
delay(1000);
} else {
dur();
delay(2000);
}
}
if (Serial.available()) {
data = Serial.read();
Serial.println(data);
bluetoothSerial.print(data);
}
}