-
Notifications
You must be signed in to change notification settings - Fork 1
/
QuadcopterTxVersion2.ino
75 lines (59 loc) · 1.21 KB
/
QuadcopterTxVersion2.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
//this is the tx code
//if left stick is reading 0,
//send 0 to rx so that it wont fly.
/*
Ranges for flight:
THROTTLE:0 -> 200
ROLL:1000 -> 1200, -1200 -> -1000
PITCH:10000 -> 10200, -10200 -> -10000
YAW:20000 -> 20200, -20200 -> 20000
flightMode0(): 100000
flightMode1(): 200000
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int
LeftStickX = 14, //A0
LeftStickY = 15, //A1
RightStickX = 16, //A2
RightStickY = 17; //A3
const byte address[5] = {'R','o','M','e','O'};
RF24 radio(9, 10);
long command;
bool sending;
void setup()
{
pinMode(LeftStickX, INPUT);
pinMode(LeftStickY, INPUT);
pinMode(RightStickX, INPUT);
pinMode(RightStickY, INPUT);
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.setRetries(2, 15)
radio.openWritingPipe(address);
}
void loop()
{
int THROTTLE, ROLL, PITCH, YAW;
YAW =
analogRead(LeftStickX);
YAW =
map(YAW, 0,1023,-20200, 20200);
THROTTLE =
analogRead(LeftStickY);
THROTTLE =
map(THROTTLE,0,1023,0,200);
ROLL =
analogRead(RightStickX);
ROLL =
map(ROLL,0,1023,-1200,1200);
PITCH =
analogRead(RightStickY);
PITCH =
map(PITCH,,0,1023,-10200,10200)
radio.write(YAW, THROTTLE, ROLL, PITCH &sizeof(command));
}
void OutOfRange()
{
}