openDogV3

Форк
0
/
Remote.ino 
223 строки · 5.5 Кб
1
#include <SPI.h>
2
#include <nRF24L01.h>
3
#include <RF24.h>
4

5
#include <Wire.h>  // Comes with Arduino IDE
6
#include <LiquidCrystal_I2C.h>
7

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
10

11
unsigned long previousMillis = 0;
12
const long interval = 20;
13

14
int but1;
15
int but2;
16
int but3;
17
int but4;
18

19
int sw1;
20
int sw2;
21
int sw3;
22
int sw4;
23
int sw5;
24

25
int axis1;
26
int axis2;
27
int axis3;
28
int axis4;
29
int axis5;
30
int axis6;
31

32
String count;
33

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
38

39
    int16_t menuDown;  
40
    int16_t Select;    
41
    int16_t menuUp;  
42
    int16_t toggleBottom;  
43
    int16_t toggleTop; 
44
    int16_t toggle1;
45
    int16_t toggle2;
46
    int16_t mode;  
47
    int16_t RLR;
48
    int16_t RFB;
49
    int16_t RT;
50
    int16_t LLR;
51
    int16_t LFB;
52
    int16_t LT;
53

54
};
55

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
59
  int16_t mode;
60
  int16_t count;
61
};
62

63
int remoteFlag = 0;
64

65
SEND_DATA_STRUCTURE mydata_send;
66
RECEIVE_DATA_STRUCTURE_REMOTE mydata_remote;
67

68
RF24 radio(14, 10); // CE, CSN
69
const byte addresses[][6] = {"00001", "00002"};
70

71

72
void setup() {  
73

74
  lcd.init();  // initialize the lcd 
75
  lcd.backlight();
76

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);
86
  
87
  pinMode(A1, INPUT);
88
  pinMode(A2, INPUT);
89
  pinMode(A4, INPUT);
90
  pinMode(A5, INPUT);
91
  pinMode(A6, INPUT);
92
  pinMode(A7, INPUT);
93
  
94
  radio.begin();
95
  radio.openWritingPipe(addresses[1]); // 00001
96
  radio.openReadingPipe(1, addresses[0]); // 00002
97
  radio.setPALevel(RF24_PA_MIN);
98

99
  radio.stopListening();
100

101
  lcd.begin(20,4);   // Initialize the lcd for 20 chars 4 lines, turn on backlight
102

103
  lcd.setCursor(0,0);
104
  lcd.print("Everything Remote   ");
105
  lcd.setCursor(0,1);
106
  lcd.print("XRobots.co.uk       ");
107

108
  Serial.begin(115200);
109
 
110
    
111
}
112

113
void loop() {
114

115
     unsigned long currentMillis = millis();
116
         if (remoteFlag == 0 && currentMillis - previousMillis >= 10) { 
117

118
              previousMillis = currentMillis;  
119

120
              but1 =  digitalRead(2);
121
              but2 =  digitalRead(3);
122
              but3 =  digitalRead(0);
123
              but4 =  digitalRead(1);
124

125
              sw1 = digitalRead(4);
126
              sw2 = digitalRead(5);
127
              sw3 = digitalRead(6);
128
              sw4 = digitalRead(8);
129
              sw5 = digitalRead(7);
130

131
                           
132
              if (but1 == 0) {
133
                mydata_send.menuDown = 1;
134
              }
135
              else {
136
                mydata_send.menuDown = 0;
137
              }
138

139
              if (but4 == 0) {
140
                mydata_send.Select = 1;
141
              }
142
              else {
143
                mydata_send.Select = 0;
144
              }
145
                            
146
              if (but2 == 0) {
147
                mydata_send.menuUp = 1;
148
              }
149
              else {
150
                mydata_send.menuUp = 0;
151
              }
152

153
              
154
              
155
              if (sw2 == 0) {
156
                mydata_send.toggleBottom = 1;
157
              }
158
              else {
159
                mydata_send.toggleBottom = 0;
160
              }
161
              
162
              if (sw1 == 0) {
163
                mydata_send.toggleTop = 1;
164
              }
165
              else {
166
                mydata_send.toggleTop = 0;
167
              }
168

169
              //******************
170

171
              if (sw3 == 0) {
172
                mydata_send.toggle1 = 1;
173
              }
174
              else {
175
                mydata_send.toggle1 = 0;
176
              }
177
              
178
              if (but3 == 0) {
179
                mydata_send.toggle2 = 1;
180
              }
181
              else {
182
                mydata_send.toggle2 = 0;
183
              } 
184
                       
185
              axis1 = analogRead(A5);
186
              axis2 = analogRead(A4);
187
              axis3 = analogRead(A6);
188
              axis4 = analogRead(A3);
189
              axis5 = analogRead(A2);
190
              axis6 = analogRead(A1);            
191

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
194

195
              // reverse walking & reverse all controls (twist is unaffected because CW and CCW and still the same no matter which way around it is)
196
              
197
              if (sw5 == 0) {
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
202
              }
203
              
204
              axis6 = map(axis6,0,1023,1023,0);   // reverse some axis due to physical wiring            
205
             
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;              
212

213
              radio.write(&mydata_send, sizeof(SEND_DATA_STRUCTURE));               
214
              
215
         }        
216
        
217

218

219
      
220

221

222

223
  }  // end of main loop
224

225

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.