-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessing_fadecandy_webcam.pde
More file actions
66 lines (53 loc) · 1.69 KB
/
Processing_fadecandy_webcam.pde
File metadata and controls
66 lines (53 loc) · 1.69 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
import gohai.glvideo.*;
GLCapture video;
OPC opc;
final int boxesAcross = 2;
final int boxesDown = 2;
final int ledsAcross = 8;
final int ledsDown = 8;
// initialized in setup()
float spacing;
int x0;
int y0;
void setup()
{
size(640, 480, P2D); // Important to note the renderer
String[] devices = GLCapture.list(); // Get the list of cameras connected to the Pi
int deviceId = getCameraDevice(devices);
video = new GLCapture(this, devices[deviceId], 640, 480, 25);
opc = new OPC(this, "127.0.0.1", 7890); // Connect to the local instance of fcserver
spacing = (float)min(height / (boxesDown * ledsDown + 1), width / (boxesAcross * ledsAcross + 1));
x0 = (int)(width - spacing * (boxesAcross * ledsAcross - 1)) / 2;
y0 = (int)(height - spacing * (boxesDown * ledsDown - 1)) / 2;
final int boxCentre = (int)((ledsAcross - 1) / 2.0 * spacing); // probably using the centre in the ledGrid8x8 method
int ledCount = 0;
for (int y = 0; y < boxesDown; y++) {
for (int x = 0; x < boxesAcross; x++) {
opc.ledGrid8x8(ledCount, x0 + spacing * x * ledsAcross + boxCentre, y0 + spacing * y * ledsDown + boxCentre, spacing, 0, false, false);
ledCount += ledsAcross * ledsDown;
}
}
video.start();
}
void draw()
{
background(0);
if (video.available()) { // If the camera is sending new data, capture that data
video.read();
}
image(video, 0, 0, width, height);
}
// find a likely match for a connected camera
int getCameraDevice(String[] devices)
{
int deviceId = 0;
if (devices.length > 0) {
for (int i = 0; i < devices.length; i++) {
if (devices[i].contains("mmal service")) {
deviceId = i;
break;
}
}
}
return deviceId;
}