-
Notifications
You must be signed in to change notification settings - Fork 1
/
LED_RECEIVER_CODE.ino
90 lines (78 loc) · 1.69 KB
/
LED_RECEIVER_CODE.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
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int msg[1];
RF24 radio(9,10);//check your pin number on RF24 github check you have the right
//pin nu2mber for the arduino you're using. this pin is diffrent for diffrent arduino models.
const uint64_t pipe = 0xF0F0F0F0D2L;
int mot1 = 5;
int mot2 = 6;
int mot3 = 7;
int mot4 = 8;
byte addresses[][6] = {"0"};
void setup(void)
{
pinMode(mot1 , OUTPUT);
pinMode(mot2 , OUTPUT);
pinMode(mot3 , OUTPUT);
pinMode(mot4 , OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();
}
void loop(void)
{
if(radio.available()){
bool done = false;
while (!done) {
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111) {
//delay(10);
forward();
}
else if(msg[0] == 222){
back();
}
else if(msg[0] == 333 ){
right();
}
else if(msg[0] == 444){
left();
}
else{
stopcar();
}
}}}
void forward(){
digitalWrite(mot1 , HIGH);
digitalWrite(mot2 , LOW);
digitalWrite(mot3 , HIGH);
digitalWrite(mot4 , LOW);
}
void back(){
digitalWrite(mot1 , LOW);
digitalWrite(mot2 , HIGH);
digitalWrite(mot3 , LOW);
digitalWrite(mot4 , HIGH);
}
void right(){
digitalWrite(mot1 , HIGH);
digitalWrite(mot2 , LOW);
digitalWrite(mot3 , LOW);
digitalWrite(mot4 , HIGH);
}
void left(){
digitalWrite(mot1 , LOW);
digitalWrite(mot2 , HIGH);
digitalWrite(mot3 , HIGH);
digitalWrite(mot4 , LOW);
}
void stopcar(){
digitalWrite(mot1 , LOW);
digitalWrite(mot2 , LOW);
digitalWrite(mot3 , LOW);
digitalWrite(mot4 , LOW);
}