-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRF Reciever.cpp
163 lines (82 loc) · 1.83 KB
/
NRF Reciever.cpp
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
NRF RECIEVER
//connection for rf receiver
//GND = GND
//DATA = 12
//VCC = 5V
#include
//connection for motors
//motor one int enA = 10;
int in1 = 9; int in2 = 8;
// motor two int enB = 11;
int in3 = 7;
int in4 = 6;
void setup() { vw_set_ptt_inverted(true);
// Required for DR3100 vw_set_rx_pin(12);
vw_setup(4000);
// Bits per sec
// set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
Serial.begin(9600); vw_rx_start();
// Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = 2;
if (vw_get_message(buf, &buflen))
// Non-blocking
{
Serial.print(buf[0]) ;
Serial.println(buf[1]);
if(buf[0]=='f'){ Serial.print("forward");
Serial.println(buf[1]);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA,255);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enB,255);
}
if(buf[0]=='b') { Serial.print("backward");
Serial.println(buf[1]);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA,255);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enB,255);
}
if(buf[0]=='s'){ Serial.print("stop");
Serial.println(buf[1]);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enA,255);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
analogWrite(enB,255);
}
if(buf[0]=='l'){ Serial.print("left");
Serial.println(buf[1]);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA,255);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enB,255);
}
if(buf[0]=='r'){ Serial.print("right");
Serial.println(buf[1]);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA,255);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enB,255);
}
}
}