-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbPprocessingV06.pde
364 lines (307 loc) · 11.5 KB
/
bbPprocessingV06.pde
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
//processing pixel capture for advenced mame and puzzlepubble
//By Fab and Phil from Tetalab
//http://www.tetalab.org
//https://github.com/tetalab/Puzzle-Bobble
//This installation was made with
//Arduino 1.0.2 IDE
//Arduino duemillanove / Arduino Uno board
//Use StandardFrimata example on the arduino
//Use common cathode RGB strip leds with a ULN2003A
//Use this pinout
// Player one Red PWM 3, Green PWM 5, Blue PWM 6
// Player one Red PWM 9, Green PWM 10, Blue PWM 11
// board shematics avilable here ==> https://raw.github.com/tetalab/Puzzle-Bobble/master/arduino_board.jpg
//Use Advancedmame ==> here ttp://sourceforge.net/projects/advancemame/files/advancemame/1.2/advancemame-1.2-windows-x86.zip/download?_test=updater&utm_expid=65835818-0
//Use this version of puzzlebobble pbobble.zip ==> here http://www.rom-world.com/file.php?id=22341
//Processing 1.5 with this sketch https://github.com/tetalab/Puzzle-Bobble/blob/master/bbPprocessingV06.pde
//with the firmata librarie http://playground.arduino.cc/interfacing/processing
//More infomation here http://www.firmata.org/wiki/Main_Page
//simple test for firmata : http://www.firmata.org/wiki/Main_Page#Firmata_Test_Program
import processing.serial.*;
import cc.arduino.*;
Arduino arduino; //Use the StandardFirmata on the Arduino (IDE Arduino 1.0.2)
import java.awt.Robot;
import java.awt.Color;
Robot PixelBot; //Robot class
Color pixelColor; //Color class
//Current RGB player 1
int pixelColor_r;
int pixelColor_g;
int pixelColor_b;
//Previous RGB player 1
int PrevpixelColor_r;
int PrevpixelColor_g;
int PrevpixelColor_b;
//Current RGB player 2
int pixelColor_r2;
int pixelColor_g2;
int pixelColor_b2;
//Previous RGB player 2
int PrevpixelColor_r2;
int PrevpixelColor_g2;
int PrevpixelColor_b2;
//Pixel position on 800x600 screen resolution for player 1
int originalX1 = 181;
int originalY1 = 514;
//Pixel position on 800x600 screen resolution for player 2
int originalX2 = 581;
int originalY2= 514;
//Variable to store "reel" pixel position after calculation made on the setup part
int reelX1 = 0;
int reelY1 = 0;
int reelX2 = 0;
int reelY2 = 0;
PVector player1;
PVector player2;
void setup()
{
arduino = new Arduino(this, Arduino.list()[0], 57600);
size (400,300);
background(0);
PrevpixelColor_r = 0;
PrevpixelColor_g = 0;
PrevpixelColor_b = 0;
PrevpixelColor_r2 = 0;
PrevpixelColor_g2 = 0;
PrevpixelColor_b2 = 0;
println("screen.width ="+ screen.width);
println("screen.height ="+ screen.height);
//Caluculation for "reel" pixel position
reelX1 = (int) (((float)screen.width/(float)800) * (float)originalX1);
reelX2 = (int) (((float)screen.width/(float)800) * (float)originalX2);
reelY1 = (int) (((float)screen.height/(float)600) * (float)originalY1);
reelY2 = (int) (((float)screen.height/(float)600) * (float)originalY2);
player1=new PVector(reelX1,reelY1); // player 1 pixel position
player2=new PVector(reelX2,reelY2); // player 2 pixel position
println("Pixel 1 = "+ reelX1 +"," + reelY1);
println("Pixel 2 = "+ reelX2 +"," + reelY2);
try
{
PixelBot = new Robot();
pixelColor = new Color(0,0,0);
}
catch (Exception e)
{
println("Robot class not supported");
exit();
}
}
void checkColor (int player)
{
int redPB [] = {209,0,0}; // color in puzzle bobble (RGB format)
int redPB2 [] = {208,0,0};
int Ared[] = {255,0,0}; // color send to Arduino (RGB format)
int orangePB [] = {247,115,0};
int orangePB2 [] = {246,114,0};
int Aorange[] = {255,100,0};
int greenPB [] = {0,171,0};
int greenPB2 [] = {0,170,0};
int Agreen[] = {0,255,0};
int bluePB [] = {0,39,246};
int bluePB2 [] = {0,37,245};
int Ablue[] = {0,0,255};
int yellowPB [] = {210,172,0};
int yellowPB2 [] = {209,171,0};
int Ayellow[] = {255,255,0};
int violetPB [] = {122,0,170};
int violetPB2 [] = {121,0,169};
int Aviolet[] = {255,0,255};
int greyPB [] = {115,114,152};
int greyPB2 [] = {114,113,151};
int Agrey[] = {50,70,90};
if (player == 1)
{
if (((pixelColor_r == redPB[0]) && (pixelColor_g == redPB[1]) && (pixelColor_b == redPB[2]))
||((pixelColor_r == redPB2[0]) && (pixelColor_g == redPB2[1]) && (pixelColor_b == redPB2[2])))
{
rect(100,200,100,100);
fill(Ared[0],Ared[1],Ared[2]);
println("Red P1");
arduino.analogWrite(3, Ared[0]);
arduino.analogWrite(5, Ared[1]);
arduino.analogWrite(6, Ared[2]);
}
else if (((pixelColor_r == greenPB[0]) && (pixelColor_g == greenPB[1]) && (pixelColor_b == greenPB[2]))
||((pixelColor_r == greenPB2[0]) && (pixelColor_g == greenPB2[1]) && (pixelColor_b == greenPB2[2])))
{
rect(100,200,100,100);
fill(Agreen[0],Agreen[1],Agreen[2]);
println("Green P1");
arduino.analogWrite(3, Agreen[0]);
arduino.analogWrite(5, Agreen[1]);
arduino.analogWrite(6, Agreen[2]);
}
else if (((pixelColor_r == bluePB[0]) && (pixelColor_g == bluePB[1]) && (pixelColor_b == bluePB[2]))
||((pixelColor_r == bluePB2[0]) && (pixelColor_g == bluePB2[1]) && (pixelColor_b == bluePB2[2])))
{
rect(100,200,100,100);
fill(Ablue[0],Ablue[1],Ablue[2]);
println("Blue P1");
arduino.analogWrite(3, Ablue[0]);
arduino.analogWrite(5, Ablue[1]);
arduino.analogWrite(6, Ablue[2]);
}
else if (((pixelColor_r == yellowPB[0]) && (pixelColor_g == yellowPB[1]) && (pixelColor_b == yellowPB[2]))
||((pixelColor_r == yellowPB2[0]) && (pixelColor_g == yellowPB2[1]) && (pixelColor_b == yellowPB2[2])))
{
rect(100,200,100,100);
fill(Ayellow[0],Ayellow[1],Ayellow[2]);
println("Yellow P1");
arduino.analogWrite(3, Ayellow[0]);
arduino.analogWrite(5, Ayellow[1]);
arduino.analogWrite(6, Ayellow[2]);
}
else if (((pixelColor_r == violetPB[0]) && (pixelColor_g == violetPB[1]) && (pixelColor_b == violetPB[2]))
||((pixelColor_r == violetPB2[0]) && (pixelColor_g == violetPB2[1]) && (pixelColor_b == violetPB2[2])))
{
rect(100,200,100,100);
fill(Aviolet[0],Aviolet[1],Aviolet[2]);
println("Violet P1");
arduino.analogWrite(3, Aviolet[0]);
arduino.analogWrite(5, Aviolet[1]);
arduino.analogWrite(6, Aviolet[2]);
}
else if (((pixelColor_r == greyPB[0]) && (pixelColor_g == greyPB[1]) && (pixelColor_b == greyPB[2]))
||((pixelColor_r == greyPB2[0]) && (pixelColor_g == greyPB2[1]) && (pixelColor_b == greyPB2[2])))
{
rect(100,200,100,100);
fill(Agrey[0],Agrey[1],Agrey[2]);
println("Grey P1");
arduino.analogWrite(3, Agrey[0]);
arduino.analogWrite(5, Agrey[1]);
arduino.analogWrite(6, Agrey[2]);
}
else if (((pixelColor_r == orangePB[0]) && (pixelColor_g == orangePB[1]) && (pixelColor_b == orangePB[2]))
|| ((pixelColor_r == orangePB2[0]) && (pixelColor_g == orangePB2[1]) && (pixelColor_b == orangePB2[2])))
{
rect(100,200,100,100);
fill(Aorange[0],Aorange[1],Aorange[2]);
println("Orange P1");
arduino.analogWrite(3, Aorange[0]);
arduino.analogWrite(5, Aorange[1]);
arduino.analogWrite(6, Aorange[2]);
}
else
{
rect(100,200,100,100);
fill(255,255,255);
println("Unknown P1");
arduino.analogWrite(3, 0);
arduino.analogWrite(5, 0);
arduino.analogWrite(6, 0);
}
}
if (player == 2)
{
if (((pixelColor_r2 == redPB[0]) && (pixelColor_g2 == redPB[1]) && (pixelColor_b2 == redPB[2]))
||((pixelColor_r2 == redPB2[0]) && (pixelColor_g2 == redPB2[1]) && (pixelColor_b2 == redPB2[2])))
{
rect(200,200,100,100);
fill(Ared[0],Ared[1],Ared[2]);
println("Red P2");
arduino.analogWrite(9, Ared[0]);
arduino.analogWrite(10, Ared[1]);
arduino.analogWrite(11, Ared[2]);
}
else if (((pixelColor_r2 == greenPB[0]) && (pixelColor_g2 == greenPB[1]) && (pixelColor_b2 == greenPB[2]))
||((pixelColor_r == greenPB2[0]) && (pixelColor_g == greenPB2[1]) && (pixelColor_b == greenPB2[2])))
{
rect(200,200,100,100);
fill(Agreen[0],Agreen[1],Agreen[2]);
println("Green P2");
arduino.analogWrite(9, Agreen[0]);
arduino.analogWrite(10, Agreen[1]);
arduino.analogWrite(11, Agreen[2]);
}
else if (((pixelColor_r2 == bluePB[0]) && (pixelColor_g2 == bluePB[1]) && (pixelColor_b2 == bluePB[2]))
||((pixelColor_r2 == bluePB2[0]) && (pixelColor_g2 == bluePB2[1]) && (pixelColor_b2 == bluePB2[2])))
{
rect(200,200,100,100);
fill(Ablue[0],Ablue[1],Ablue[2]);
println("Blue P2");
arduino.analogWrite(9, Ablue[0]);
arduino.analogWrite(10, Ablue[1]);
arduino.analogWrite(11, Ablue[2]);
}
else if (((pixelColor_r2 == yellowPB[0]) && (pixelColor_g2 == yellowPB[1]) && (pixelColor_b2 == yellowPB[2]))
||((pixelColor_r2 == yellowPB2[0]) && (pixelColor_g2 == yellowPB2[1]) && (pixelColor_b2 == yellowPB2[2])))
{
rect(200,200,100,100);
fill(Ayellow[0],Ayellow[1],Ayellow[2]);
println("Yellow P2");
arduino.analogWrite(9, Ayellow[0]);
arduino.analogWrite(10, Ayellow[1]);
arduino.analogWrite(11, Ayellow[2]);
}
else if (((pixelColor_r2 == violetPB[0]) && (pixelColor_g2 == violetPB[1]) && (pixelColor_b2 == violetPB[2]))
||((pixelColor_r2 == violetPB[0]) && (pixelColor_g2 == violetPB[1]) && (pixelColor_b2 == violetPB[2])))
{
rect(200,200,100,100);
fill(Aviolet[0],Aviolet[1],Aviolet[2]);
println("Violet P2");
arduino.analogWrite(9, Aviolet[0]);
arduino.analogWrite(10, Aviolet[1]);
arduino.analogWrite(11, Aviolet[2]);
}
else if (((pixelColor_r2 == greyPB[0]) && (pixelColor_g2 == greyPB[1]) && (pixelColor_b2 == greyPB[2]))
||((pixelColor_r2 == greyPB2[0]) && (pixelColor_g2 == greyPB2[1]) && (pixelColor_b2 == greyPB2[2])))
{
rect(200,200,100,100);
fill(Agrey[0],Agrey[1],Agrey[2]);
println("Grey P2");
arduino.analogWrite(9, Agrey[0]);
arduino.analogWrite(10, Agrey[1]);
arduino.analogWrite(11, Agrey[2]);
}
else if (((pixelColor_r2 == orangePB[0]) && (pixelColor_g2 == orangePB[1]) && (pixelColor_b2 == orangePB[2]))
|| ((pixelColor_r2 == orangePB2[0]) && (pixelColor_g2 == orangePB2[1]) && (pixelColor_b2 == orangePB2[2])))
{
rect(200,200,100,100);
fill(Aorange[0],Aorange[1],Aorange[2]);
println("Orange P2");
arduino.analogWrite(9, Aorange[0]);
arduino.analogWrite(10, Aorange[1]);
arduino.analogWrite(11, Aorange[2]);
}
else
{
rect(200,200,100,100);
fill(255,255,255);
println("Unknown P2");
arduino.analogWrite(9, 0);
arduino.analogWrite(10, 0);
arduino.analogWrite(11, 0);
}
}
}
void draw()
{
pixelColor = PixelBot.getPixelColor((int)player1.x,(int)player1.y); //get player 1 pixel position
pixelColor_r = pixelColor.getRed();
pixelColor_g = pixelColor.getGreen();
pixelColor_b = pixelColor.getBlue();
rect(100,100,100,100);
fill(pixelColor_r,pixelColor_g,pixelColor_b);
if (pixelColor_r != PrevpixelColor_r || pixelColor_g != PrevpixelColor_g || pixelColor_b != PrevpixelColor_b) // if new
{
print("1 - Red " + pixelColor_r + " Green " + pixelColor_g + " blue " + pixelColor_b + " ==>");
checkColor(1);
PrevpixelColor_r = pixelColor_r;
PrevpixelColor_g = pixelColor_g;
PrevpixelColor_b = pixelColor_b;
}
pixelColor = PixelBot.getPixelColor((int)player2.x,(int)player2.y); //get player 2 pixel position
pixelColor_r2 = pixelColor.getRed();
pixelColor_g2 = pixelColor.getGreen();
pixelColor_b2 = pixelColor.getBlue();
rect(200,100,100,100);
fill(pixelColor_r2,pixelColor_g2,pixelColor_b2);
if (pixelColor_r2 != PrevpixelColor_r2 || pixelColor_g2 != PrevpixelColor_g2 || pixelColor_b2 != PrevpixelColor_b2)// if new
{
print("2 - Red " + pixelColor_r2 + " Green " + pixelColor_g2 + " Blue " + pixelColor_b2+ " ==>");
checkColor(2);
PrevpixelColor_r2 = pixelColor_r2;
PrevpixelColor_g2 = pixelColor_g2;
PrevpixelColor_b2 = pixelColor_b2;
}
}