1#include <nRF24L01.h>
2#include <printf.h>
3#include <RF24.h>
4#include <RF24_config.h>
5#include <SPI.h>
6#include "RF24.h"
7
8
9const int enbA = 3;
10const int enbB = 5;
11
12const int IN1 = 2;
13const int IN2 = 4;
14const int IN3 = 7;
15const int IN4 = 6;
16
17int RightSpd = 130;
18int LeftSpd = 130;
19
20int data[2];
21
22
23RF24 radio(9,10);
24
25const uint64_t pipe = 0xE8E8F0F0E1LL;
26
27void setup(){
28
29 pinMode(enbA, OUTPUT);
30 pinMode(enbB, OUTPUT);
31 pinMode(IN1, OUTPUT);
32 pinMode(IN2, OUTPUT);
33 pinMode(IN3, OUTPUT);
34 pinMode(IN4, OUTPUT);
35
36 Serial.begin(9600);
37 radio.begin();
38 radio.openReadingPipe(1, pipe);
39 radio.startListening();
40 }
41
42void loop(){
43 if (radio.available()){
44 radio.read(data, sizeof(data));
45
46 if(data[0] > 380){
47
48 analogWrite(enbA, RightSpd);
49 analogWrite(enbB, LeftSpd);
50 digitalWrite(IN1, HIGH);
51 digitalWrite(IN2, LOW);
52 digitalWrite(IN3, HIGH);
53 digitalWrite(IN4, LOW);
54 }
55
56 if(data[0] < 310){
57
58 analogWrite(enbA, RightSpd);
59 analogWrite(enbB, LeftSpd);
60 digitalWrite(IN1, LOW);
61 digitalWrite(IN2, HIGH);
62 digitalWrite(IN3, LOW);
63 digitalWrite(IN4, HIGH);
64 }
65
66 if(data[1] > 180){
67
68 analogWrite(enbA, RightSpd);
69 analogWrite(enbB, LeftSpd);
70 digitalWrite(IN1, HIGH);
71 digitalWrite(IN2, LOW);
72 digitalWrite(IN3, LOW);
73 digitalWrite(IN4, HIGH);
74 }
75
76 if(data[1] < 110){
77
78 analogWrite(enbA, RightSpd);
79 analogWrite(enbB, LeftSpd);
80 digitalWrite(IN1, LOW);
81 digitalWrite(IN2, HIGH);
82 digitalWrite(IN3, HIGH);
83 digitalWrite(IN4, LOW);
84 }
85
86 if(data[0] > 330 && data[0] < 360 && data[1] > 130 && data[1] < 160){
87
88 analogWrite(enbA, 0);
89 analogWrite(enbB, 0);
90 }
91 }
92}