-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alici.ino
80 lines (75 loc) · 2.02 KB
/
Alici.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
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int data[2];
const int Motor1_Ileri = 4;//Sağ Motor
const int Motor1_Geri = 2;
const int Motor1_PWM = 3;
const int Motor2_Ileri = 7;//Sol Motor
const int Motor2_Geri = 6;
const int Motor2_PWM = 5;
void setup()
{
pinMode(Motor1_Ileri,OUTPUT);
pinMode(Motor1_Geri,OUTPUT);
pinMode(Motor1_PWM,OUTPUT);
pinMode(Motor2_Ileri,OUTPUT);
pinMode(Motor2_Geri,OUTPUT);
pinMode(Motor2_PWM,OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}
void loop() {
if ( radio.available() ) //Eğer sinyal algılarsan...
{
int y = data[1];
int x = data[0];
radio.read( data, sizeof(data) );
if(y >= 400 && y <= 600) {
digitalWrite(Motor1_Ileri,LOW);
digitalWrite(Motor1_Geri,LOW);
analogWrite(Motor1_PWM,0);
digitalWrite(Motor2_Ileri,LOW);
digitalWrite(Motor2_Geri,LOW);
analogWrite(Motor2_PWM,0);
}
if(y >= 800 && y <= 1023) {
digitalWrite(Motor1_Ileri,LOW);
digitalWrite(Motor1_Geri,HIGH);
analogWrite(Motor1_PWM,255);
digitalWrite(Motor2_Ileri,LOW);
digitalWrite(Motor2_Geri,HIGH);
analogWrite(Motor2_PWM,255);
}
if(y >= 0 && y <= 450) {
digitalWrite(Motor1_Ileri,HIGH);
digitalWrite(Motor1_Geri,LOW);
analogWrite(Motor1_PWM,255);
digitalWrite(Motor2_Ileri,HIGH);
digitalWrite(Motor2_Geri,LOW);
analogWrite(Motor2_PWM,255);
}
if(x >= 0 && x <= 450) {
digitalWrite(Motor1_Ileri,LOW);
digitalWrite(Motor1_Geri,HIGH);
analogWrite(Motor1_PWM,255);
digitalWrite(Motor2_Ileri,HIGH);
digitalWrite(Motor2_Geri,LOW);
analogWrite(Motor2_PWM,255);
}
if(x >= 600 && x <= 1023) {
digitalWrite(Motor1_Ileri,HIGH);
digitalWrite(Motor1_Geri,LOW);
analogWrite(Motor1_PWM,255);
digitalWrite(Motor2_Ileri,LOW);
digitalWrite(Motor2_Geri,HIGH);
analogWrite(Motor2_PWM,255);
}
}
}