Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

error, disabling serialEvent() for //./COM3

$
0
0
Hi...
I want to do the transition of images with respect to the intensity of light strike on LDR.
I manipulate the output of LDR from 1 to 10 in arduino and there is 10 images in processing, i want those images in processing to change with respect to the LDR output. 
But i am getting this error......

error, disabling serialEvent() for //./COM3
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.serial.Serial.serialEvent(Unknown Source)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Caused by: java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:3541)
at processing.core.PApplet.image(PApplet.java:11912)
at transition_of_images.serialEvent(transition_of_images.java:65)
... 8 more

Here is my code 

  1. import processing.serial.*;
  2. Serial myPort;

  3. PImage[] imgs;

  4. int nbr_of_images;
  5. float transitionFrames = 30;
  6. int displayFrames = 50;
  7. float fadeValue = 0;

  8. float img_Actual;
  9. float img_Next;


  10. void setup() {
  11.   size(1440, 900);

  12.   nbr_of_images = 10;  
  13.   imgs = new PImage[nbr_of_images];  
  14.  println(Serial.list());
  15. // print a list of all available ports
  16. myPort = new Serial(this, Serial.list()[1], 9600);
  17. myPort.bufferUntil('\n');
  18. for (int i = 0; i < nbr_of_images; i++)
  19. {
  20.   imgs[i] = loadImage(nf(i, 2) + ".JPG");
  21. }
  22. }


  23. void draw () {
  24.  // everything happens in the serialEvent()
  25.  }
  26.  
  27.  void serialEvent (Serial myPort) {
  28.  // get the ASCII string:
  29.  String inString = myPort.readStringUntil('\n');
  30.  

  31.  // convert to an int and map to the screen height:
  32.  float inByte = float(inString); 
  33.  println(inByte);
  34.   
  35.       // full opacity for image in background
  36.       tint(255);
  37.       image(imgs[int(img_Actual)], 0, 0, width, height);
  38.       
  39.       // fade foreground-image using tint()
  40.       tint(255, lerp(0, 255, fadeValue));
  41.       image(imgs[int(img_Next)], 0, 0, width, height);
  42.             
  43.             // change image and reset fadeValue
  44.   if (frameCount % (displayFrames) == 0)
  45.   {
  46.     fadeValue = 0;
  47.     img_Actual = img_Next;
  48.     img_Next = inByte;
  49.   }
  50.    // increase opacity of second image
  51.       fadeValue = fadeValue+1/transitionFrames;
    }

Need your valuable suggestions...
Thanking you in anticipation

Viewing all articles
Browse latest Browse all 1768

Trending Articles