-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tx (Arduino Nano).txt
73 lines (67 loc) · 1.27 KB
/
Tx (Arduino Nano).txt
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
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CNS, CE
int text[8] = {0};
const byte address[6] = "00001";
void setup() {
pinMode(2,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();
}
int x = 0;
int y = 0;
int ML = 0;
int MR = 0;
int xCordMin = 330;
int xCordMax = 370;
int yCordMin = 360;
int yCordMax = 380;
int xSpeed = 6;
int ySpeed = 6;
void loop()
{
int roll = analogRead(A0);
int pitch = analogRead(A1);
//int yaw = analogRead(A2);
if(roll > xCordMax)
x = xSpeed;
if(roll < xCordMin)
x = -1*xSpeed;
if(pitch > yCordMax)
y = -1*ySpeed;
if(pitch < yCordMin)
y = ySpeed;
if(roll > xCordMin && roll < xCordMax)
x = 0;
if(pitch > yCordMin && pitch < yCordMax)
y = 0;
if(roll == 511 || roll == 0)
x = 0;
if(pitch == 511 || pitch == 0)
y = 0;
if(digitalRead(2) == LOW)
ML = 1; //click
else
ML = 0;
if(digitalRead(4) == LOW)
MR = 1;
else
MR = 0;
text[0] = 9; //for start delimeter
text[1] = x;
text[2] = y;
text[3] = ML;
text[4] = MR;
text[5] = xSpeed;
text[6] = ySpeed;
radio.write(&text, sizeof(text));
delay(20);
}