File tree 1 file changed +9
-14
lines changed
1 file changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,7 @@ final int bytesPerFrame = cameraPixelCount * cameraBytesPerPixel;
22
22
PImage myImage;
23
23
byte [] frameBuffer = new byte [bytesPerFrame];
24
24
25
- void setup ()
26
- {
25
+ void setup () {
27
26
size (640 , 480 );
28
27
29
28
// if you have only ONE serial port active
@@ -43,15 +42,14 @@ void setup()
43
42
myPort. write(1 );
44
43
}
45
44
46
- void draw ()
47
- {
45
+ void draw () {
48
46
PImage img = myImage. copy();
49
47
img. resize(640 , 480 );
50
48
image (img, 0 , 0 );
51
49
}
52
50
53
51
void serialEvent (Serial myPort ) {
54
- // read the saw bytes in
52
+ // read the received bytes
55
53
myPort. readBytes(frameBuffer);
56
54
57
55
// access raw bytes via byte buffer
@@ -62,17 +60,14 @@ void serialEvent(Serial myPort) {
62
60
63
61
while (bb. hasRemaining()) {
64
62
// read 16-bit pixel
65
- byte p = bb. get();
66
-
63
+ byte pixelValue = bb. get();
67
64
68
65
// set pixel color
69
- myImage .pixels [i++ ] = color (Byte . toUnsignedInt(p));
70
-
71
- // Let the Arduino sketch know we received all pixels
72
- // and are ready for the next frame
73
- if (i == cameraPixelCount){
74
- myPort. write(1 );
75
- }
66
+ myImage. pixels [i++ ] = color (Byte . toUnsignedInt(pixelValue));
76
67
}
68
+
77
69
myImage. updatePixels();
70
+ // Let the Arduino sketch know we received all pixels
71
+ // and are ready for the next frame
72
+ myPort. write(1 );
78
73
}
You can’t perform that action at this time.
0 commit comments