File tree Expand file tree Collapse file tree 1 file changed +9
-14
lines changed
Expand file tree Collapse file tree 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;
2222PImage myImage;
2323byte [] frameBuffer = new byte [bytesPerFrame];
2424
25- void setup ()
26- {
25+ void setup () {
2726 size (640 , 480 );
2827
2928 // if you have only ONE serial port active
@@ -43,15 +42,14 @@ void setup()
4342 myPort. write(1 );
4443}
4544
46- void draw ()
47- {
45+ void draw () {
4846 PImage img = myImage. copy();
4947 img. resize(640 , 480 );
5048 image (img, 0 , 0 );
5149}
5250
5351void serialEvent (Serial myPort ) {
54- // read the saw bytes in
52+ // read the received bytes
5553 myPort. readBytes(frameBuffer);
5654
5755 // access raw bytes via byte buffer
@@ -62,17 +60,14 @@ void serialEvent(Serial myPort) {
6260
6361 while (bb. hasRemaining()) {
6462 // read 16-bit pixel
65- byte p = bb. get();
66-
63+ byte pixelValue = bb. get();
6764
6865 // 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));
7667 }
68+
7769 myImage. updatePixels();
70+ // Let the Arduino sketch know we received all pixels
71+ // and are ready for the next frame
72+ myPort. write(1 );
7873}
You can’t perform that action at this time.
0 commit comments