5
#include <Wire.h> // Comes with Arduino IDE
6
#include <LiquidCrystal_I2C.h>
8
// Set the pins on the I2C chip used for LCD connections (Some LCD use Address 0x27 and others use 0x3F):
9
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
11
unsigned long previousMillis = 0;
12
const long interval = 20;
34
struct SEND_DATA_STRUCTURE{
35
//struct __attribute__((__packed__)) SEND_DATA_STRUCTURE{
36
//put your variable definitions here for the data you want to send
37
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
56
struct RECEIVE_DATA_STRUCTURE_REMOTE{
57
//put your variable definitions here for the data you want to receive
58
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
65
SEND_DATA_STRUCTURE mydata_send;
66
RECEIVE_DATA_STRUCTURE_REMOTE mydata_remote;
68
RF24 radio(14, 10); // CE, CSN
69
const byte addresses[][6] = {"00001", "00002"};
74
lcd.init(); // initialize the lcd
77
pinMode(0, INPUT_PULLUP);
78
pinMode(1, INPUT_PULLUP);
79
pinMode(2, INPUT_PULLUP);
80
pinMode(3, INPUT_PULLUP);
81
pinMode(4, INPUT_PULLUP);
82
pinMode(5, INPUT_PULLUP);
83
pinMode(6, INPUT_PULLUP);
84
pinMode(7, INPUT_PULLUP);
85
pinMode(8, INPUT_PULLUP);
95
radio.openWritingPipe(addresses[1]); // 00001
96
radio.openReadingPipe(1, addresses[0]); // 00002
97
radio.setPALevel(RF24_PA_MIN);
99
radio.stopListening();
101
lcd.begin(20,4); // Initialize the lcd for 20 chars 4 lines, turn on backlight
104
lcd.print("Everything Remote ");
106
lcd.print("XRobots.co.uk ");
108
Serial.begin(115200);
115
unsigned long currentMillis = millis();
116
if (remoteFlag == 0 && currentMillis - previousMillis >= 10) {
118
previousMillis = currentMillis;
120
but1 = digitalRead(2);
121
but2 = digitalRead(3);
122
but3 = digitalRead(0);
123
but4 = digitalRead(1);
125
sw1 = digitalRead(4);
126
sw2 = digitalRead(5);
127
sw3 = digitalRead(6);
128
sw4 = digitalRead(8);
129
sw5 = digitalRead(7);
133
mydata_send.menuDown = 1;
136
mydata_send.menuDown = 0;
140
mydata_send.Select = 1;
143
mydata_send.Select = 0;
147
mydata_send.menuUp = 1;
150
mydata_send.menuUp = 0;
156
mydata_send.toggleBottom = 1;
159
mydata_send.toggleBottom = 0;
163
mydata_send.toggleTop = 1;
166
mydata_send.toggleTop = 0;
172
mydata_send.toggle1 = 1;
175
mydata_send.toggle1 = 0;
179
mydata_send.toggle2 = 1;
182
mydata_send.toggle2 = 0;
185
axis1 = analogRead(A5);
186
axis2 = analogRead(A4);
187
axis3 = analogRead(A6);
188
axis4 = analogRead(A3);
189
axis5 = analogRead(A2);
190
axis6 = analogRead(A1);
192
axis2 = map(axis2,0,1023,1023,0); // reverse some axis due to physical wiring
193
axis4 = map(axis4,0,1023,1023,0); // reverse some axis due to physical wiring
195
// reverse walking & reverse all controls (twist is unaffected because CW and CCW and still the same no matter which way around it is)
198
axis1 = map(axis1,0,1023,1023,0); // reverse axis
199
axis2 = map(axis2,0,1023,1023,0); // reverse axis
200
axis4 = map(axis4,0,1023,1023,0); // reverse axis
201
axis5 = map(axis5,0,1023,1023,0); // reverse axis
204
axis6 = map(axis6,0,1023,1023,0); // reverse some axis due to physical wiring
206
mydata_send.RFB = axis1;
207
mydata_send.RLR = axis2;
208
mydata_send.RT = axis3;
209
mydata_send.LFB = axis4;
210
mydata_send.LLR = axis5;
211
mydata_send.LT = axis6;
213
radio.write(&mydata_send, sizeof(SEND_DATA_STRUCTURE));
223
} // end of main loop