Repository navigation
Expand file tree
/
Copy pathRemote.ino
More file actions
227 lines (172 loc) · 3.9 KB
/
Copy pathRemote.ino
File metadata and controls
227 lines (172 loc) · 3.9 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//-----------------------------------------------------------------
//
// ArduiBAG - Michaël d'AURIA
// 27/08/2014
//
// Remote control part
//
//-----------------------------------------------------------------
#include <SoftwareSerial.h> // Serial library
//----------------------------
// Hardware configuration
//----------------------------
// Joystick PIN
#define JOY1 0 // Analog
#define JOY2 1 // Analog
#define JOY3 2 // Digital
// LED 1 PIN
#define LED1R 5 //LED 1 Red
#define LED1G 6 //LED 1 Greed
#define LED1B 7 //LED 1 Blue
// LED 2 PIN
#define LED2R 8 //LED 2 Red
#define LED2G 9 //LED 2 Ged
#define LED2B 10 //LED 2 Blue
//Oldcode
char oldcode=1;
//----------------------------------
// SETUP
//----------------------------------
void setup() {
//JOSTICK SWITCH
pinMode(JOY3, INPUT);
//LED 1 initialisation
pinMode(LED1R, OUTPUT);
pinMode(LED1G, OUTPUT);
pinMode(LED1B, OUTPUT);
//LED 2 initialisation
pinMode(LED2R, OUTPUT);
pinMode(LED2G, OUTPUT);
pinMode(LED2B, OUTPUT);
// enable internal pullup - will then read high unless button is pressed to connect to Gnd
digitalWrite (JOY3, HIGH); // Activate switch
// Serial communication for BLUETOOTH
Serial.begin(9600); // Or 9600, 38400 depending on your firmware version
//-------------------
// TESTING LEDS
//-------------------
//Blue
LED (1, 1);
LED (2, 1);
delay (800);
// Green
LED (1, 10);
LED (2, 10);
delay (800);
// Red
LED (1, 100);
LED (2, 100);
delay (800);
//---------------------------
// waiting for the bag
//---------------------------
while(!Serial.available()) {
LED (1, 1);
LED (2, 1);
delay(500);
LED (1, 0);
LED (2, 0);
delay(500);
Serial.write('a');
}
}
//----------------------------------
// MAIN LOOP
//----------------------------------
void loop() {
char code;
code = AJoyst();
if (code and code!=oldcode) {
Serial.print(code);
oldcode = code;
}
if (Serial.available()){
allumeLED(Serial.read());
}
}
//----------------------------------
// JOYSTICK TESTER
//----------------------------------
char AJoyst() {
int val1 = 0;
int val2 = 0;
int val3 = 0;
val1 = analogRead(JOY1);
delay(100);
val2 = analogRead(JOY2);
//delay(100);
val3 = digitalRead(JOY3);
//CLICK
if (val1>510 and val1<530 and val2>510 and val2<530 and val3==0)return 'a';
//LEFT
if (val1>510 and val1<530 and val2>1000)return 'A';
//RIGHT
if (val1>510 and val1<530 and val2<20)return 'B';
//DOWN
if (val1<20 and val2>510 and val2<530)return 'C';
//UP
if (val1>1000 and val2>510 and val2<530)return 'D';
//UP-LEFT
//if (val1<20 and val2<20) return 'E';
//haut-droit
//if (val1>1000 and val2<10) return 'F';
//bas-gauche
//if (val1<20 and val2>1000) return 'G';
//bas-droite
//if (val1>1000 and val2>1000) return 'H';
return 0;
}
void allumeLED(char action) {
switch (action) {
case 'B' :
LED(1, 110);
LED(2, 0);
oldcode = 1;
break;
case 'A' :
LED(1, 0);
LED(2, 11);
oldcode = 1;
break;
case 'R' :
LED(1, 110);
break;
case 'L' :
LED (2, 110);
break;
case 'S' :
LED (1, 100);
LED (2, 100);
break;
case 'T' :
LED (1, 111);
LED (2, 100);
break;
case 'M' :
LED (1, 101);
LED (2, 101);
break;
default:
LED(1,0);
LED(2,0);
break;
}
}
//LED
void LED(char ledNumber, char colorCode) {
char r,g,b;
r = colorCode / 100 % 10;
g = colorCode / 10 % 10;
b = colorCode % 10;
//LED 1
if (ledNumber==1) {
digitalWrite(LED1R, r);
digitalWrite(LED1G, g);
digitalWrite(LED1B, b);
} else {
//LED 2
digitalWrite(LED2R, r);
digitalWrite(LED2G, g);
digitalWrite(LED2B, b);
}
}